Created
August 6, 2013 07:28
-
-
Save dzwillpower/6162783 to your computer and use it in GitHub Desktop.
自定义Toast Custom Toast
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void PopToast() { | |
// 获取LayoutInflater对象,该对象能把XML文件转换为与之一直的View对象 | |
LayoutInflater inflater = getLayoutInflater(); | |
// 根据指定的布局文件创建一个具有层级关系的View对象 | |
// 第二个参数为View对象的根节点,即LinearLayout的ID | |
View layout = inflater.inflate(R.layout.sort_toast, | |
(ViewGroup) findViewById(R.id.toast_layout_root)); | |
Toast toast = new Toast(this); | |
// 设置Toast的位置 | |
toast.setGravity(Gravity.BOTTOM, 0, 0); | |
toast.setDuration(Toast.LENGTH_LONG); | |
// 让Toast显示为我们自定义的样子 | |
toast.setView(layout); | |
toast.show(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:id="@+id/toast_layout_root" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:gravity="center" | |
android:layout_marginBottom="10px" | |
android:paddingBottom="20px" | |
android:orientation="vertical" > | |
<ImageView | |
android:id="@+id/image" | |
android:layout_width="wrap_content" | |
android:src="@drawable/sort_toast" | |
android:layout_height="fill_parent"/> | |
</LinearLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment