当前位置:网站首页>Toast will display a simple prompt message on the program interface
Toast will display a simple prompt message on the program interface
2022-07-07 17:36:00 【XLMN】
toast A simple prompt message will be displayed on the program interface
This information prompt box is used to generate simple prompt messages for users , It has the following characteristics
1、toast Prompt messages will not live in focus
2、toast The prompt message will disappear automatically after a period of time
send total Method of generating prompt message
1、 call toast Constructor , or maketext() The static method creates one total object
2、 call toast Method to set the alignment of the message prompt , Margins, etc
3、 call toast Of show Method to show him
total The function and usage are relatively simple , Generally, simple text prompt information is displayed , If you need to display something like a picture , Complex tips like lists , It is generally recommended to use dialog boxes to complete , Or use toast Construction example , Calling setview Method to set the toast According to the view Components
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.bt);
Button bt = (Button) findViewById(R.id.bt01);
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Create a toast Prompt information Toast.LENGTH_LONG) Prompt information time
Toast ts = Toast.makeText(MainActivity.this, " I wish you a happy and bitter day , Mountains, rivers, stars and moon all make congratulatory gifts ",
Toast.LENGTH_LONG);
ts.show();
}
});
Button bt1 = (Button) findViewById(R.id.bt02);
// Set the prompt message with picture
bt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Create a total Prompt information
Toast ts = new Toast(MainActivity.this);
// Set the prompt display position
ts.setGravity(Gravity.CENTER, 0, 0);
// Create a imageview
ImageView image = new ImageView(MainActivity.this);
image.setImageResource(R.drawable.love);
// Create a linearlayout Containers
LinearLayout ly = new LinearLayout(MainActivity.this);
// Add pictures and original... To the container view
ly.addView(image);
// Create a textview
TextView tv = new TextView(MainActivity.this);
tv.setText("love mia");
// Set the size and font color of the text box
tv.setTextSize(24);
tv.setTextColor(Color.MAGENTA);
ly.addView(tv);
// Set display custom view
ts.setView(ly);
// Set up toast Display time
ts.setDuration(Toast.LENGTH_LONG);
ts.show();
}
});
}
}
边栏推荐
- Siggraph 2022 best technical paper award comes out! Chen Baoquan team of Peking University was nominated for honorary nomination
- Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
- mysql实现两个字段合并成一个字段查询
- 《世界粮食安全和营养状况》报告发布:2021年全球饥饿人口增至8.28亿
- actionBar 导航栏学习
- 本周小贴士131:特殊成员函数和`= default`
- notification是显示在手机状态栏的通知
- 让保险更“保险”!麒麟信安一云多芯云桌面中标中国人寿, 助力金融保险信息技术创新发展
- Solidity函数学习
- 【可信计算】第十次课:TPM密码资源管理(二)
猜你喜欢
随机推荐
服务器彻底坏了,无法修复,如何利用备份无损恢复成虚拟机?
serachview的功能和用法
Sator a lancé le jeu web 3 "satorspace" et a lancé huobi
User defined view essential knowledge, Android R & D post must ask 30+ advanced interview questions
[Fantan] how to design a test platform?
Functions and usage of ratingbar
How to mount the original data disk without damage after the reinstallation of proxmox ve?
actionBar 导航栏学习
使用popupwindow創建对话框风格的窗口
【可信计算】第十次课:TPM密码资源管理(二)
L1-019 谁先倒(Lua)
麒麟信安操作系统衍生产品解决方案 | 存储多路径管理系统,有效提高数据传输可靠性
The mail server is listed in the blacklist. How to unblock it quickly?
LeetCode 890(C#)
【信息安全法律法規】複習篇
第3章业务功能开发(用户登录)
LeetCode刷题day49
第3章业务功能开发(安全退出)
百度地图自定义样式向右拖拽导致全球地图经度0度无法正常显示
Functions and usage of imageswitch