如何改变android里Toast现实字体的颜色需
1个回答
2016-02-02 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517181
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
LayoutInflater inflater = LayoutInflater
.from(getApplicationContext());
View view = inflater.inflate(R.layout.my_toast,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView textView = (TextView) view.findViewById(R.id.text);
SpannableString ss = new SpannableString("扫描成功");
ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 4,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
mytoast.xml
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:layout_marginTop="800dip"
android:textSize="25dip"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="50dip"
android:textColor="@color/black" />
</LinearLayout>
.from(getApplicationContext());
View view = inflater.inflate(R.layout.my_toast,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView textView = (TextView) view.findViewById(R.id.text);
SpannableString ss = new SpannableString("扫描成功");
ss.setSpan(new ForegroundColorSpan(Color.RED), 0, 4,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(view);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
mytoast.xml
<?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="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:layout_marginTop="800dip"
android:textSize="25dip"
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="50dip"
android:textColor="@color/black" />
</LinearLayout>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询