Android开发之Toast

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

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

第一种系统默认的方式:

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>

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

 

posted @ 2014-08-03 10:36  小破孩123  阅读(537)  评论(0编辑  收藏  举报