Samsung の電話を Wi-Fi ネットワークに接続すると、青色のトーストが表示されることがあります。トーストの色をカスタマイズするのを手伝ってくれる人はいますか?
例えば:
Samsung の電話を Wi-Fi ネットワークに接続すると、青色のトーストが表示されることがあります。トーストの色をカスタマイズするのを手伝ってくれる人はいますか?
例えば:
このように:
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
ます
出力:
これを試して:-
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();
要件に合わせてカスタム Toast ビューを作成できます。http://developer.android.com/guide/topics/ui/notifiers/toasts.htmlの「カスタム トースト ビューの作成」というセクションを参照してください。