1.Toast提示框
1.1 绑定按钮点击事件
1.2 toast.makeText方法 (设置时间的长短 三秒 和 五秒)
1.3 所处的位置
文字版
|
1
2
3
|
Toast ashortToast = Toast.makeText(MainActivity.this , "显示一个简短的Toast", Toast.LENGTH_SHORT);
ashortToast.setGravity(Gravity.CENTER, 100, 0);//所处的位置左右。。上下
ashortToast.show();
|
图片版本
|
1
2
3
4
5
6
7
|
public void onClick(View v) {
Toast imaToast=Toast.makeText(MainActivity.this , "显示一个图片的Toast", Toast.LENGTH_LONG);
ImageView imageView= new ImageView(MainActivity.this);
imageView.setImageResource(R.drawable.ic_launcher);
imaToast.setView(imageView);
imaToast.show();
}
|
|
1
2
3
4
5
6
7
|
public void onClick(View v) {
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View toast_view = inflater.inflate(R.layout.toast_layout, null);
Toast toast = new Toast(MainActivity.this);
toast.setView(toast_view);
toast.show();
}
|
其中toast_layout为新建的xml格式
百度云代码分享:http://pan.baidu.com/s/1gdCYHj1
转载于:https://my.oschina.net/TAOH/blog/526049