Android开发之Tomast

第一次在博客园发布文章,就把我刚弄明白的关于Android开发中的提示设置,分享给大家。

Tomast是Android中经常用到的一个方法,用于简单的用户提示,经过摸索我发现了Tomast的两种使用方式,先不扯别的,分享一下,还望大师指教。

第一种系统默认的方式:

Toast.makeText(getApplicationContext(), "系统自带提示形式", Toast.LENGTH_SHORT).show();

第二种自定义方式:

Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);//设置显示的位置
toast.setDuration(Toast.LENGTH_LONG);//设置显示的时间

toast.setView(getLayoutInflater().inflate(R.layout.activity_two,null));//设置自定义的视图

toast.show();

在自定义中显示的视图:

<LinearLayout
  android:id="@+id/linearLayout1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
>
  <ImageView
    android:background="@drawable/fire_eye_alien"

    android:layout_width="50dip"
    android:layout_height="50dip"
  />
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text="自定义形式提示"
    android:textSize="20dip"
  />
</LinearLayout>

个人感觉对于自定义类型的Tomast,难点在于视图的引入,希望大神能给出更多的指导。

 

Android开发之Tomast,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。