我使用以下代码显示一条toast消息作为if语句的结果:
Toast.makeText(getBaseContext(), "Please Enter Price", Toast.LENGTH_SHORT).show();
它在白色背景上显示为白色文本,因此无法阅读!我的问题是,如何更改吐司文本的颜色?
发布于 2011-07-14 10:01:51
您可以创建自定义Toast
view
以满足您的要求。请参阅http://developer.android.com/guide/topics/ui/notifiers/toasts.html上标题为“创建自定义Toast视图”的部分
发布于 2011-07-14 10:03:54
您可能希望创建自定义Toast
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#DAAA"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
</LinearLayout>
-
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello! This is a custom toast!");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
发布于 2015-03-11 15:51:06
更改吐司的背景色和吐司文本的背景色的最简单方法是:
View view;
TextView text;
Toast toast;
toast.makeText(this, resId, Toast.LENGTH_SHORT);
view = toast.getView();
text = (TextView) view.findViewById(android.R.id.message);
text.setTextColor(getResources().getColor(R.color.black));
text.setShadowLayer(0,0,0,0);
view.setBackgroundResource(R.color.white);
toast.show();
https://stackoverflow.com/questions/6687666
复制相似问题