【问题标题】:Making a Color Toast in Android在 Android 中制作彩色吐司
【发布时间】:2014-02-20 06:16:28
【问题描述】:

当我将三星手机连接到 wifi 网络时,有时会出现蓝色吐司。任何人都可以帮助自定义吐司的颜色。

例如:

【问题讨论】:

标签: android toast textcolor android-toast


【解决方案1】:

试试这个:-

SpannableString text = new SpannableString("Please Wait !!!!! ");  


        text.setSpan(new ForegroundColorSpan(Color.BLUE), 0, 41, 0);  
        Toast.makeText(c.getApplicationContext(),text , Toast.LENGTH_LONG).show();

另一种方式:- 制作一个 xml / customToast.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/toast_layout"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="8dp"
              android:background="#DAAA"
              >
    <ImageView android:src="@drawable/img1"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginRight="8dp"
               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#FFF"
              />
</LinearLayout>

活动中:-

LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.customToast,
                               (ViewGroup) findViewById(R.id.toast_layout));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("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();

【讨论】:

    【解决方案2】:

    像这样:

    LayoutInflater inflater = youractivity.this.getLayoutInflater();
                View layout = inflater.inflate(R.layout.custom_toast,
                        null);
                TextView text = (TextView) layout.findViewById(R.id.tvtoast);
                text.setText("No Internet Connection");
                text.setTextColor(Color.BLACK);
                Toast toast = new Toast(getActivity());
                toast.setView(layout);
                toast.setDuration(100);
                toast.show();
    

    根据您的需要制作自己的布局custom_toast.xml 并将Color 设置为TextView 文本

    输出:

    【讨论】:

      【解决方案3】:

      您可以创建自定义 Toast 视图以满足您的要求。请参阅 http://developer.android.com/guide/topics/ui/notifiers/toasts.html 上标题为“创建自定义 Toast 视图”的部分

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-30
        • 2015-04-23
        • 1970-01-01
        相关资源
        最近更新 更多