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();
时间: 2024-10-07 12:09:49