
前提・実現したいこと
ダイアログの「はい、いいえ」の背景色と文字色の変更方法が分からない。
なお、背景色は「はい」、「いいえ」の後ろだけではなく、行(フッター)として全体の色を変えたい。
以下、ソースの
alertDlg.setPositiveButton("はい", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int a=a; } }); alertDlg.setNegativeButton("いいえ", null);
に対する部分の背景色、文字色を変更したいです。
該当のソースコード
java
1 // カスタムビューを設定 2 LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); 3 View layout = inflater.inflate(R.layout.time_dialog, (ViewGroup) findViewById(R.id.time_layout)); 4 5 // アラーとダイアログ を生成 6 final AlertDialog.Builder alertDlg = new AlertDialog.Builder(this); 7 // タイトル部分のTextView 8 TextView textView = new TextView(this); 9 // タイトルの背景色 10 textView.setBackgroundColor(ContextCompat.getColor(this, R.color.dialog_background_color)); 11 // タイトルの文字色 12 textView.setTextColor(getResources().getColor(R.color.font_color)); 13 textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 14 int paddingLeftRight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()); 15 int paddingTopBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()); 16 textView.setPadding(paddingLeftRight, paddingTopBottom, paddingLeftRight, paddingTopBottom); 17 // タイトルのテキスト設定 18 textView.setText(getString(R.string.time_title)); 19 // テキストサイズ 20 textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20); 21 // タイトル部分にTextViewをセット 22 alertDlg.setCustomTitle(textView); 23 24 alertDlg.setView(layout); 25 26 alertDlg.setPositiveButton("はい", new DialogInterface.OnClickListener() { 27 @Override 28 public void onClick(DialogInterface dialog, int which) { 29 int a=a; 30 } 31 }); 32 alertDlg.setNegativeButton("いいえ", null); 33 34 // 表示 35 final AlertDialog dialog = alertDlg.create(); 36 dialog.show(); 37 38 // ボタンが押されたとき 39 time_button =(Button)layout.findViewById(R.id.time_button); 40 time_button.setOnClickListener(new View.OnClickListener() { 41 @Override 42 public void onClick(View v) { 43 dialog.dismiss(); 44 } 45 }); 46 47 }
試したこと
Googleで対処方法を検索し、タイトルと中のレイアウトは変更出来たが、
「はい、いいえ」の部分のみ対処方法が見つからず色を変更できない。
補足情報(FW/ツールのバージョンなど)
Android Studio3.4
Android対象API14から28


回答1件
あなたの回答
tips
プレビュー