您的位置:首页 > 移动开发 > Android开发

Android中自定义特定颜色的Toast

2015-02-01 19:57 302 查看
/**
* 展示一个特定颜色的Toast
*
* @param message
*/
protected void toast(String message) {
View toastRoot = LayoutInflater.from(context).inflate(R.layout.toast, null);
Toast toast = new Toast(context);
toast.setView(toastRoot);
TextView tv = (TextView) toastRoot.findViewById(R.id.toast_notice);
tv.setText(message);
toast.show();
}
Toast的布局文件如下

<?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:background="@drawable/toast_border">
<TextView android:id="@+id/toast_notice"
android:layout_width="wrap_content"
android:layout_height="@dimen/toast_height"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:textColor="@color/app_toast_text">
</TextView>
</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: