protected void showToast() {
// create the view
View view = inflateView(R.layout.incoming_message_panel);
// set the text in the view
TextView tv = (TextView)view.findViewById(R.id.message);
tv.setText("khtx. meet u for dinner. cul8r");
// show the toast
Toast toast = new Toast(this);
toast.setView(view);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
}
// create the view
View view = inflateView(R.layout.incoming_message_panel);
// set the text in the view
TextView tv = (TextView)view.findViewById(R.id.message);
tv.setText("khtx. meet u for dinner. cul8r");
// show the toast
Toast toast = new Toast(this);
toast.setView(view);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
}
本文介绍了一种在Android应用中创建并显示自定义Toast消息的方法。通过LayoutInflater加载布局文件,并设置特定的消息文本,然后使用Toast类展示这个自定义视图。此方法允许开发者灵活地定制消息样式。
449

被折叠的 条评论
为什么被折叠?



