android中如何设置Toast 的样式
2016-03-09 13:55
525 查看
android自带的Toast 往往样式都不是很好看,灰色的背景,看着很不舒服,下面就来写一个小的demo来改变一下Toast的样式
1.创建一个class继承Toast
2.定义两个方法来显示Toast
在上面的showText方法里面来实现具体的业务逻辑
1.创建出Toast实例
Toast toast=new Toast(context);
2.获得布局填充器,填充布局
3.找到LinearLayout里面的TextView然后将String text设置进去就好了
4.调用Toast的show();方法就可以了
1.创建一个class继承Toast
2.定义两个方法来显示Toast
public c 4000 lass CustomToast extends Toast{ public CustomToast(Context context) { super(context); } public static void showText(Context context, int id) { showText(context, context.getString(id)); } public static void showText(Context context, String text) { } }
在上面的showText方法里面来实现具体的业务逻辑
1.创建出Toast实例
Toast toast=new Toast(context);
2.获得布局填充器,填充布局
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout contentView = (LinearLayout) inflater.inflate(R.layout.toast_custom, null);
3.找到LinearLayout里面的TextView然后将String text设置进去就好了
TextView mTextView = (TextView) contentView.findViewById(R.id.toast_text); mTextView.setText(text); toast.setView(contentView);
4.调用Toast的show();方法就可以了
相关文章推荐
- Android 内存优化实例
- 给android应用程序系统的签名
- Android跑马灯实现的三种方式
- Android常用组件
- EasyPusher安卓Android手机直播推送之MediaCodec 硬编码H264格式
- Android studio如何使用SVN进行版本控制?
- Android四大组件Broadcast Receiver详解
- android开发时怎样让图片充满屏幕
- Android Studio的技巧
- 阅读《Android 从入门到精通》(30)——字体
- android独有的省内存的轻量级容器类
- GitHub Top 100的Android开源库
- ANE总结(Android+iPhone)
- 关于 Android Handler 跟 Thread 通信交互的小实例,配备了 Demo 供初学/新手小伙伴参考
- Android 快速开发框架XUtils
- Android框架设计模式(一)——Template Methods
- Android触控基础:MotionEvent
- ANDROID 一键搞定JNI创建C头文件
- Android 日常开发总结的60条技术经验
- android V7 包导入