1

Android入门第30天-Android里的Toast的使用

 1 year ago
source link: https://blog.csdn.net/lifetragedy/article/details/127926384
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

本篇带来的是: Android用于提示信息的一个控件——Toast(吐司)!Toast是一种很方便的消息提示框,会在 屏幕中显示一个消息提示框,没任何按钮,也不会获得焦点一段时间过后自动消失! 非常常用!我们通过一个例子把Toast的使用讲透!

44f1c7e510254fe894698c0a75a6cdb9.png

我们的目标是实现2个Toast。

  1. 第一个Toast我们使用的是系统默认的样式,它显示两秒后自动消失;
  2. 第二个Toast我们使用的是自定义的样式,它在屏幕的中央显示两秒后自动消失;

toast在屏幕上的闪现会有两种Duration。

  • Toast.LENGTH_SHORT,2秒;

  • LENGTH_LONG,3点5秒;

9b715971d7d7401e9ef76cb22adef921.png
  • 我们会在自定义toast里使用一个图片,我们把它放在mipmap下;
  • 我们会使用一个自定义的toast,因此需要定义一个view_toast_custom.xml文件;

view_toast_custom.xml



newCodeMoreWhite.png

 activity_main.xml



newCodeMoreWhite.png

MainActivity.java



newCodeMoreWhite.png

动手试试吧。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK