アンドロイドにカスタマイズトーストを表示する必要があります。特定の位置に表示されます。どのように画面の特定の位置にカスタムトーストを表示できますか。Androidのアクティビティでカスタムトーストを特定の位置に表示する方法
-1
A
答えて
0
1としてそれを呼び出します下のようなテキストビュー
<TextView
android:id="@+id/textView1"
android:layout_width="800dp"
android:layout_height="wrap_content"
android:background="@drawable/custom_tost_shape"
android:gravity="center_vertical|center_horizontal"
android:text="Action Successfuly Completed!"
android:textColor="#ff0000"
android:textSize="40sp"/>
2.このコードを挿入して、メッセージをパラメータとして受け取るメソッドにトーストを表示します。 myShowToastMethod(文字列のメッセージ){//コード}
LayoutInflater layoutInflater = GenApplicationId.this.getLayoutInflater();
View view = layoutInflater.inflate(R.layout.custom_toast, null);
TextView tvMessage = (TextView) view.findViewById(R.id.textView1);
tvMessage.setHeight(100);
tvMessage.setText(message);
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, -0, 230);
toast.setView(view);
toast.show();
+0
を参照することができ、私はあなたが好きです回答。どうもありがとうございました。 –
0
0
を使用するメッセージ文字列と期間を定義することができ、新しいToastオブジェクトを作成し、コンテキスト、テキストメッセージ、およびduratiに渡しますon、show()を呼び出します。
あなたが前(toast.showするために呼び出さsetGravity機能)を使用してトーストを配置することができます
toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);
0
が、この方法に
public static void showBottomToast(Context context, String msg) {
View custom_view = LayoutInflater.from(context).inflate(
R.layout.dialog_bottom_toast, null);
TextView tvMessage = (TextView) custom_view
.findViewById(R.id.tvMessage);
tvMessage.setText(msg);
showToast(context.getApplicationContext(), Gravity.FILL_HORIZONTAL
| Gravity.BOTTOM, custom_view, Toast.LENGTH_LONG);
}
public static void showToast(Context ctx, int gravity, View root,
int duration) {
final Toast mToast = new Toast(ctx);
mToast.setGravity(gravity, 0, 0);
mToast.setDuration(duration);
mToast.setView(root);
mToast.show();
}
とdialog_bottom_toast.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tvMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_margin="@dimen/marg_20"
android:text="@string/welcome"
android:maxLines="2"
android:ellipsize="end"
android:textColor="@color/blue"
android:textSize="@dimen/sp_16"
android:textStyle="bold" />
</LinearLayout>
あるを使用してみてください
0
非常に簡単カスタムトーストを実装する方法
//show custom Toast in android
private void showCustomToast(String showToast) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup) findViewById(R.id.toast_layout_root));
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText(showToast);
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
とレイアウトcustom_toast.xmlを作成することが
toast_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="@color/primary"
android:orientation="horizontal"
android:padding="10dp">
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="hello"
android:textSize="15sp"
android:textColor="#ffffff" />
</LinearLayout>
ようなレイアウトだ定義し、これを呼び出したいところはどこでもそしてちょうど
showCustomToast("Your_Message");
関連する問題
- 1. Androidのデフォルトでは、recyclerviewアイテムの特定の位置を強調表示する方法
- 2. imgNoteで特定の位置にテキストを表示します。
- 3. テキストを所定の位置に表示する方法は?
- 4. サブビューを追加して特定の位置で表示する
- 5. 特定のマーカー位置のストリートビューを表示する
- 6. Java(コンソール)の特定の配列位置を表示する
- 7. regexを特定の位置でオプションにする方法は?
- 8. スクロールで特定の位置にスクロールする方法
- 9. ブートストラップスライダでマウスの位置にツールヒント値を表示する方法
- 10. レスポンスネイティブの特定の位置にリストビューをスクロールする方法
- 11. 特定の位置のArrayListにオブジェクトを挿入する方法
- 12. Androidのインテントフィルタ特定のカテゴリのアクティビティを非表示
- 13. 特定のマウス位置にテキストボックスをドラッグアンドドロップする - キャレットまたは位置のインジケータを表示する
- 14. ios:特定の位置でカーソルを起動する方法は?
- 15. 特定のファイル位置で2文字をgrepする方法
- 16. Pythonで特定の配列位置を選択する方法
- 17. Android - DialogFragment、アクティビティのエッジとの位置合わせ方法
- 18. Androidの特定の位置にボタンをドラッグアンドドロップする
- 19. Xcode:スクロールビューの特定の位置に移動する方法
- 20. fabricjs内の特定のオブジェクト位置にナビゲートする方法
- 21. Cのリッチテキストボックスにカーソルの位置を表示する方法
- 22. Androidリサイクラーの表示アイテムの位置
- 23. FrameLayout内のアクティビティをandroidで表示する方法
- 24. android - アクティビティの終了後にダイアログを表示する方法
- 25. 条件に基づいてGridviewの特定の位置を非表示にする方法
- 26. 棒グラフの棒の位置を特定する方法は?
- 27. UITextFieldの現在のキャレット位置を特定する方法は?
- 28. テキストファイル内の文字の位置を特定する方法(C++)
- 29. sql result-setの行の位置を特定する方法は?
- 30. recyclerviewのアイテムの位置をアクティビティに取得する方法
の提案として、あなたはトーストが様々な位置に表示させたい場合は、このhttp://stackoverflow.com/a/37668673/6312749 – Abhishek