toast组件小结
- 简介:toast是“吐司”的意思,它属于android杂项组件,是一个简单的消息提示框,类似于javascript中的alert.
- 作用
- 显示文本
- 显示图片
- 显示图文
3.常用方法
show():显示消息提示框
makeText(Context context,Charsquence text,int duration):创建一个toast对象
setView(View view):该Toast显示的view组件
4.代码演示
MainActivity.class
public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void findOne(View v){
Toast.makeText(this,"显示文本",Toast.LENGTH_LONG).show();
}
public void findTwo(View v){
Toast toast = new Toast(this);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.ic_launcher);
toast.setView(imageView);
toast.setGravity(Gravity.TOP,0,0);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
}
public void findThree(View v){
Toast toast = new Toast(this); TextView tv = new TextView(this);
tv.setText("安卓开机图片"); ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.ic_launcher); LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(imageView);
layout.addView(tv);
toast.setView(layout); toast.setGravity(Gravity.CENTER,0,0);
toast.setDuration(Toast.LENGTH_LONG);
toast.show();
} }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.langdon.taiyang.androidtest.MainActivity">
<Button
android:text="toast显示文本"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toidOne"
android:onClick="findOne"
android:layout_gravity="center_horizontal"
/>
<Button
android:text="toast显示图片"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toidTwo"
android:onClick="findTwo"
android:layout_gravity="center_horizontal"/>
<Button
android:text="toast显示图文"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toidThree"
android:onClick="findThree"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
5.注意点
toast组件小结的更多相关文章
- 提示框的优化之自定义Toast组件之(二)Toast组件的业务逻辑实现
在java下org.socrates.mydiary.activity下LoginActivity下自定义一个方法showCustomerToast() public class LoginAct ...
- 微信小程序把玩(二十四)toast组件
原文:微信小程序把玩(二十四)toast组件 toast消息提示框,可用在提示一些信息,比如清楚缓存给用户一个友好的提示!或操作一些请求不想让用户有什么操作,toast也可以做到因为toast显示时其 ...
- 百度小程序自定义通用toast组件
百度小程序Toast组件 author: @TiffanysBear 百度小程序自定义通用toast组件 BdToast百度小程序自定义通用组件-github地址 需求 手百小程序的toast仅支持在 ...
- 使用Angular CDK实现一个Service弹出Toast组件
在Angular中,官方团队在开发Material组件库的同时,顺手做了一套Component dev kit,也就是在Angular世界中大名鼎鼎的CDK,这套工具包提供了非常多的前端开发的通用功能 ...
- 提示框的优化之自定义Toast组件之(三)Toast组件优化
开发步骤: 在toast_customer.xml文件中添加一个图片组件对象显示提示图片 <?xml version="1.0" encoding="utf-8&q ...
- 提示框的优化之自定义Toast组件之(一)Toast组件的布局实现
开发步骤: 在res下layout下创建一个Toast的布局资源文件toast_customer.xml 在最外层布局组件中为该布局添加android:id属性 //toast_custo ...
- 每日技术总结:Toast组件,eslint,white-space,animate,$emit
1.一个优雅的提示是网站必不可少的. 请参考:vue2.0 自定义 提示框(Toast)组件 2.ESLint使用总结 (1)在.eslintrc.js里关闭某条规则, '规则名': 'off'或0 ...
- 小程序中怎么引入wepy.js第三方toast组件
1.先安装组件 npm install wepy-com-toast --save 2.引入wepy和toast import wepy from 'wepy' import Toast from ' ...
- vue中的toast组件
首先在components新建组件文件夹 随后在toast.vue中写入弹框样式 <template> <transition name="demo"> & ...
随机推荐
- [LeetCode] Generate Parentheses 生成括号
Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...
- WPF简单模拟QQ登录背景动画
介绍 之所以说是简单模拟,是因为我不知道QQ登录背景动画是怎么实现的.这里是通过一些办法把它简化了,做成了类似的效果 效果图 大体思路 首先把背景看成是一个4行8列的点的阵距,X轴Y轴都是距离70.把 ...
- 如何用TypeScript开发微信小程序
微信小程序来了!这个号称干掉传统app的玩意儿虽然目前处于内测阶段,不过目前在应用号的官方文档里已经放出了没有内测号也能使用的模拟器了. 工具和文档可以参考官方文档:https://mp.weixin ...
- 语义网 (Semantic Web)和 web 3.0
语义网=有意义的网络. "如果说 HTML 和 WEB 将整个在线文档变成了一本巨大的书,那么 RDF, schema, 和 inference languages 将会使世界上所有的数据变 ...
- VS2013快捷键及技巧
VS2013快捷键很多,灵活使用常用快捷键及各项技巧可以让你事半功倍.下面的visual studio 2013快捷键和操作技巧你知道多少? 1.回到上一个光标位置/前进到下一个光标位置 1)回到上一 ...
- Sqlite3常用的插入方法及性能测试
最近做到的项目涉及一个大数据量缓存重传,其中要用到的sqlite技术,把自己的学习心得整理了一下. SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它包含在一个相对小的C库中. ...
- ajax实现局部刷新
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- LAMP(1) 在VirtualBox里安装Ubuntu Server
问题0.虚拟机中安装lamp环境 问题解决: 来自百度经验 问题1. 用putty远程登陆linux系统,显示network error connection refused 问题解决 问题2. my ...
- 【Android群英传】学习笔记(一)
本系列博客为笔者在学习<Android群英传>的学习总结 Android相关工具镜像连接:http://www.androiddevtools.cn/ Dalvik与ART Dalvik包 ...
- Unity Game窗口中还原Scene窗口摄像机操作 强化版
之前写的那个版本看来真的是不行啊.最近研究了一下官方第一人称脚本,人家的平滑过渡真的是没得说.借鉴了一下,写出来了一个新的比较完美的控制. 之前我们的操作是通过鼠标输入的开始坐标和转动坐标.其实官方有 ...