android自定义toast
来源:互联网 发布:网络文员兼职 编辑:程序博客网 时间:2024/05/16 04:13
首先给toast一个布局view
<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:background="#0a0084FD"> <TextView android:id="@+id/toastText" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="center" android:textColor="@color/colorPrimaryDark" android:textSize="16sp" /></FrameLayout>toast正文代码部分,创建一个自己的toast类
import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.widget.TextView;import android.widget.Toast;import honghu.com.hong_hu.R;/** * Created by Administrator on 2017/5/12. */public class MyToast { private Toast mToast; /** * @param context 一个上下文对象 * @param text toast的文本内容 * @param duration toast的时间显示 * 在构造方法中将自定义toast进行初始化 */ public MyToast(Context context, CharSequence text, int duration) { View view = LayoutInflater.from(context).inflate(R.layout.mytoast_view, null); TextView toastText = (TextView) view.findViewById(R.id.toastText); mToast = new Toast(context); toastText.setText(text); mToast.setDuration(duration); mToast.setView(view); } public static MyToast makeText(Context context, CharSequence text, int duration) { return new MyToast(context, text, duration); } public void show() { if (mToast != null) { mToast.show(); } } public void setGravity(int gravity, int xOffset, int yOffset) { mToast.setGravity(gravity, xOffset, yOffset); }}
0 0
- android自定义Toast视图
- Android中自定义Toast
- Android自定义Toast样式
- android Toast 自定义样式
- 自定义Toast - Android代码
- android中自定义toast
- Android 自定义Toast
- android自定义Toast视图
- android 自定义toast
- 自定义Android Toast
- android自定义toast
- Android Toast自定义
- android自定义toast
- Android之自定义Toast
- Android 自定义Toast实现
- android 自定义toast
- Android Toast自定义
- android 自定义toast
- 解决打开迅雷就出现自动播放广告和小视频问题
- GitHub上README.md教程
- OpenStack容器化之路:Kolla项目介绍
- Servlet 数据库访问
- MapReducer程序调试技巧(搭建伪分布式集群)
- android自定义toast
- iOS基础之OC简单控件知识了解(二)
- Python+Selenium 简单的实例
- 微信小程序滚动Tab选项卡:左右可滑动切换
- 汇编程序:植入程序的程序(二)
- 《Android群英传》笔记3——Android控件架构
- 用java读取properites文件值,并且将值存入类变量(static )以方便获取
- 在ubuntu上安装Cmake、opencv2.4.9、PCL1.8、g2o
- Android 动画