自定义控件:Toast
来源:互联网 发布:大学生网络党校考试 编辑:程序博客网 时间:2024/06/07 00:44
比较简单,直接贴代码
效果图
toast的布局:custom_toast.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:background="@drawable/custom_toast" android:orientation="horizontal"> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@mipmap/ic_launcher"/> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:textColor="@android:color/white" android:textSize="20sp" android:layout_height="wrap_content" android:text=""/></LinearLayout>
custom_toast.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <corners android:radius="10dp"/> <solid android:color="#21211d"/></shape>
CustomToast
public class CustomToast { private static Toast toast; public static void showToast(Context context, String content) { if (toast == null) { View toastView = LayoutInflater.from(context).inflate(R.layout.custom_toast, null);// ImageView iv = (ImageView) toastView.findViewById(R.id.iv); TextView tv = (TextView) toastView.findViewById(R.id.tv); tv.setText(content); toast = new Toast(context); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(toastView); toast.setGravity(Gravity.CENTER, 0, 0); } toast.show(); }}
Toast
居中
Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);toast.setGravity(Gravity.CENTER,0,0);
使用
CustomToast.showToast(MainActivity.this,"已达到北京");
其它
Demo:http://git.oschina.net/customView/customtoast01
参考:自定义Toast样式
阅读全文
0 0
- 自定义控件:自定义Toast
- 自定义控件:Toast
- 提示控件之自定义Toast
- Android自定义控件之自定义Toast
- android应用程序中使用自定义Toast控件
- [android自定义控件]带有图片的Toast
- 自定义类似于安卓中的Toast控件
- 微信小程序自定义控件--toast(仿Android)
- 【android自定义控件】自定义Toast,AlterDialog,Notification <四>
- Toast控件
- 自定义Toast
- 自定义Toast
- 自定义Toast
- 自定义Toast
- 自定义toast
- 自定义toast
- 自定义Toast
- 自定义toast
- 剑指offer面试题4
- 百度笔试-度度熊回家距离
- kotlin简介(copy百度百科)
- 实训项目第三周1
- Flink提交作业的两种方式
- 自定义控件:Toast
- 229. Majority Element II
- 知识库集锦
- Windows 强制删除文件及文件夹命令 一、删除文件或目录CMD命令: rd/s/q D:\app (强制删除文件文件夹和文件夹内所有文件)del/f/s/q D:\app.txt (强
- 前端学习笔记4-jquery
- The Ultimate Guide To iPhone Resolutions
- spark2.1.0WordCountCluster
- 88. Merge Sorted Array
- soapUI(带界面的)在windows下的用法(转)