2017-07-05 2 views

答えて

0

アンドロイドの一時的なメッセージを表示するために使用されるクラス登録Toastと呼ばれています。次のように

トーストを表示するための方法は次のとおりです。 -

Toast.makeText(context,"Your message to display",Toast.LENGTH_LONG).show(); 

はここより上のToasthereをお読みください。画像を追加したり、トーストをカスタマイズしたりするには、this answerを参照してください。

0

私はカスタムトーストを使うべきだと思います。

レイアウトリソースファイルを作成します。私のリソースファイルの名前はtoast.xmlですが、必要な名前を付けてください。緑の小切手の画像を見つけて、アプリのドロウアブルフォルダに保存します。あなたのMainActivity.java

public void showCustomToast(String message) { 
    LayoutInflater inflater = getLayoutInflater(); 
    View layout = inflater.inflate(R.layout.toast, 
      (ViewGroup) findViewById(R.id.toast_layout)); 
    TextView text = (TextView) layout.findViewById(R.id.text); 
    text.setText(message); 
    Toast toast = new Toast(getApplicationContext()); 
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); 
    toast.setDuration(Toast.LENGTH_LONG); 
    toast.setView(layout); 
    toast.show(); 
} 

toast.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/toast_layout" 
android:orientation="horizontal" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:padding="10dp" 
android:background="#FFF" > 

<ImageView android:id="@+id/image" 
    android:contentDescription="Green check mark" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/green_check_mark"/> 

<TextView android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:textColor="#FF8B8B8B" 
    android:text="Registered Successfully"/> 

だけトーストを表示するshowCustomToast("Registered Successfully)を呼び出します。お役に立てれば。

+0

ありがとうalott bro –

+0

問題はありません。それが助けてくれてうれしい。 –

関連する問題