Toast
来源:互联网 发布:三茅招聘软件 编辑:程序博客网 时间:2024/05/16 17:23
Toast 能动态显示信息,并且不获取焦点。
常用方法
- Toast.makeText(context,textt,duration);//返回值为Toast
- toast.setduration(duration);//设置显示时间
- toast.setGravity(gravity,x0ffset,y0ffset);//设置toast位置
- 其中gravity有许多默认的参数可以用,第二个和第三个参数分别是x和y的偏移量
- toast.setText(s);//设置显示内容
- toast.show();//显示
实现带有图片的Tosat:
通过使用 toast.getView()的方法
example:
-------------------------------------------------------------------------------------------------------------------------
LinearLayout toast_layout = (LinearLyaout)toast.getView();
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.*****);
toast_layout.addView(iv,0 );
toast.show();
自定义Toast
example:
-------------------------------------------------------------------------------------------------------------------------
//先做创建布局.xml文件
//使用了线性布局
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:text=" 自定义Toast"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/topimg"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:gravity="center"
android:text="内容"
/>
/>
//main_activity中的方法
private void showToast(){
LayoutInflater inflater = LayoutInflater.from(this);
View toast_view = inflater.inflate(R.layout.****,null);
//将布局文件转换成 VIew对象
Toast toast = new Toast(this);
toast.setView(view);
toast.show();
}
0 0
- Toast
- Toast
- Toast
- Toast
- Toast
- Toast
- toast
- Toast
- Toast
- toast
- toast
- Toast
- Toast
- toast
- Toast
- Toast
- Toast
- Toast
- sdau-2 1010
- numpy中的nonzero()的用法
- Android控件SeekBar
- MySql 数据库操作
- numpy 中array参数'f'与order='f'区别
- Toast
- 北京林业大学“计蒜客”杯程序设计竞赛 网络赛 A题 换瓶盖
- C++ primer第二节笔记
- Dialog 对话框
- 60. Permutation Sequence
- Notification 通知栏
- 常见排序算法总结
- Caesar_Ciphers(凯撒移位)python描述
- flex mxml调用as文件