官方封装的Toast
Toast.makeText(this, "提示", Toast.LENGTH_SHORT).show;
自定义Toast
一、思路:使用Toast对象的setView()方法
二、实现
1、首先准备一个Toast的布局文件toast_msg.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout"
android:orientation="vertical"
android:background="@drawable/toast_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/toast_txt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:paddingLeft="10dp"
android:layout_marginRight="10dp"
android:text=""
android:textColor="#ffffff"/>
</LinearLayout>
Toast的背景
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 背景渐变-->
<gradient
android:angle="-90"
android:endColor="#330000ff"
android:startColor="#3300ff00"/>
<corners android:radius=