当前位置:网站首页>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();
}
});
}
}
边栏推荐
猜你喜欢
随机推荐
Flask build API service SQL configuration file
本周小贴士#136:无序容器
【网络攻防原理与技术】第4章:网络扫描技术
Sator推出Web3游戏“Satorspace” ,并上线Huobi
Repair method of firewall system crash and file loss, material cost 0 yuan
[fan Tan] after the arrival of Web3.0, where should testers go? (ten predictions and suggestions)
LeetCode 535(C#)
[video / audio data processing] Shanghai daoning brings you elecard download, trial and tutorial
PLC: automatically correct the data set noise, wash the data set | ICLR 2021 spotlight
Function and usage of textswitch text switcher
rpcms获取指定分类下的文章的方法
How to implement safety practice in software development stage
DevOps 的运营和商业利益指南
What is cloud computing?
状态模式 - Unity(有限状态机)
DatePickerDialog和trimepickerDialog
datepicket和timepicket,日期、时间选择器的功能和用法
麒麟信安加入宁夏商用密码协会
【信息安全法律法规】复习篇
麒麟信安中标国网新一代调度项目!