0

Samsung の電話を Wi-Fi ネットワークに接続すると、青色のトーストが表示されることがあります。トーストの色をカスタマイズするのを手伝ってくれる人はいますか?

例えば:

ここに画像の説明を入力

4

3 に答える 3

1

このように:

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を作成し、必要に応じてテキストに設定ColorTextViewます

出力:

ここに画像の説明を入力

于 2014-02-20T06:21:47.910 に答える
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();
于 2014-02-20T06:22:41.507 に答える
0

要件に合わせてカスタム Toast ビューを作成できます。http://developer.android.com/guide/topics/ui/notifiers/toasts.htmlの「カスタム トースト ビューの作成」というセクションを参照してください。

于 2014-02-20T06:20:46.260 に答える