AlertDialogのPositive、Negative、Neutralボタンをテキストではなくドローアブルに設定しようとしています。
私はこれまでこれを使用して成功しています:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setPositiveButton("Save", new DialogInterface.OnClickListener() {...})
.setNeutralButton("Trash", new DialogInterface.OnClickListener() {...})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {...});
AlertDialog alert = builder.create();
alert.show();
Button button0 = alert.getButton(AlertDialog.BUTTON_POSITIVE);
button0.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_save), null, null, null);
button0.setText("");
Button button1 = alert.getButton(AlertDialog.BUTTON_NEUTRAL);
button1.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_delete), null, null, null);
button1.setText("");
Button button2 = alert.getButton(AlertDialog.BUTTON_NEGATIVE);
button2.setCompoundDrawablesWithIntrinsicBounds(this.getResources().getDrawable(R.drawable.ic_menu_close_clear_cancel), null, null, null);
button2.setText("");
ただし、これは回避策です。なぜなら、私は実際には事後にテキストを消去しているだけだからです。私の問題は、ある種のテキストを設定しないとボタンをインスタンス化できないように見えることです。
最初から「[blank_space]」を設定すると、画像が左に押された場合と同じ結果が得られます。同じ場所にnullまたは""を設定すると、ボタンがまったくない状態でAlertDialogが描画されます。あなたはそれがここの写真でどのように左に押すかを見ることができます:
とにかく写真だけを使うことはありますか?私の単純な状況で翻訳を処理しようとするよりもはるかに良いでしょう。