Android基础TOP4:Tost的使用

Activity:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.top4.MainActivity" >

    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

JAVA:

View view=getLayoutInflater().inflate(R.layout.activity_main,null);
            //定义一个Toast
        Toast ts=new Toast(this);
        //将该Tosat输出到 View
        ts.setView(view);
        //设置Toast时间
        ts.setDuration(2000);
        //设置Tost的位置 
        ts.setGravity(Gravity.BOTTOM|Gravity.RIGHT,20,30);
        //最后要记得加.show();不加就不会显示
        ts.show();

 

posted @ 2017-04-08 15:53  AndrioidCSY  阅读(331)  评论(0编辑  收藏  举报