Android自定义边框背景颜色的Toast
来源:互联网 发布:大数据毕业设计本科 编辑:程序博客网 时间:2024/05/17 23:50
直接上代码:
1.主函数:
View toastRoot = getActivity().getLayoutInflater().inflate(R.layout.my_toast, null); Toast toast = new Toast(getActivity()); toast.setView(toastRoot); TextView tv = (TextView) toastRoot.findViewById(R.id.TextViewInfo); tv.setText("说明,这是一个自定义边框和底角的提示框"); toast.show();
默认的Toast无法实现我们所需要的效果,那么我们只能自定义布局文件,另外Toast的背景形状是圆角的,所以我们需要自定义Shape文件。
2.在drawable-hdpi下新建一个my_border.xml文件
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ff0000ff"/> <stroke android:width="1dp" android:color="#FFFFFFFF" /> <padding android:left="7dp" android:top="7dp" android:right="7dp" android:bottom="7dp" /> <corners android:radius="4dp" /></shape>
3.新建一个布局文件my_toast.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:background="@drawable/my_border" android:id="@+id/TextViewInfo" android:text="这是一个自定义背景颜色的提示框" android:layout_gravity="center_vertical" android:textColor="#ff00ff00" android:layout_height="wrap_content" /></LinearLayout>
阅读全文
0 0
- Android自定义边框背景颜色的Toast
- Android自定义边框背景的Toast
- android界面设计——自定义边框背景的Toast
- Android中自定义特定颜色的Toast
- android 背景是透明的,边框是有颜色的
- Android 自定义toast总结:纯文本,带图像,带标题栏及自定义背景文字颜色
- android EditText 自定义边框 背景
- android 自定义边框和背景
- android button设置边框背景颜色
- 自定义android控件EditText 自定义边框 背景
- 自定义android控件EditText 自定义边框 背景
- Android 自定义有边框的背景选择图片
- Android 自定义有边框的背景选择图片
- Android Toast 自定义背景、图片 随心使用
- MFC修改button的颜色、背景、边框
- MFC修改button的颜色、背景、边框
- MFC修改button的颜色、背景、边框
- Android:自定义的Toast
- 安卓学习日记(二)四大组件(一)活动——Activity详解
- Java反射机制与动态代理(二)
- springmvc controller 面向切面编程,实现数据查询的缓存功能
- Android Multimedia框架总结(二十三)MediaCodec补充及MediaMuxer引入(附案例)
- 百度网盟内容匹配广告和展示广告相关技术
- Android自定义边框背景颜色的Toast
- 《App后台开发运维和架构实践》读书笔记
- Hibernate Validator验证框架中@NotEmpty、@NotNull、@NotBlank 的区别
- 我的Kotlin For Android之路基础篇(一)
- vue 子组件向父组件传递参数
- 设计原则:组合复用原则
- BP神经网络-前向传播
- C语言快速排序之sort排序
- 学习笔记 山外K60库图像解压函数原理(底层代码详解)