は、私は現在、このようになります警告ダイアログがあります。 Current Alert DialogAlertDialogカスタムボタンアンドロイドを作成するには?
をしかし、私は「YES」と「NO」ボタンが背景を持っているか、彼らだけではなく、テキストのボタンがあるように見えるしたいと思います。 AlertDialogのカスタムテーマを実装しようとしましたが、変更できるのは「警告」テキストの色を変更することだけです。
"YES"と "NO"の代わりに実際のボタンが表示されるように、アラートダイアログのテーマをカスタマイズする最も効率的で簡単な方法は何でしょうか?
これが私の現在のres /値/のstyles.xmlファイル
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorAccent">@color/PCCA_blue</item>
</style>
<style name="customAlertDialog" parent="@android:style/Theme.Holo.Dialog">
<item name="android:textColor">@color/red</item>
</style>
であり、これは私が構築し、見せるAlertDialogです。何かアドバイスが高く評価され
private void alert(final String action){
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.customAlertDialog));
String message = "";
switch(action) {
case "upload":
message = "Are you sure you want to upload the counted quantities?\n\nIt may take a few minutes to reflect your changes.";
break;
case "download":
message = "Downloading new worksheets may overwrite existing counted quantities, do you want to continue?\n\n" +
"NOTE: You may want to upload counts first.\n\n" +
"(Changed counted quantities will still be available for upload)";
break;
default:
message = action;
break;
}
alertDialogBuilder.setTitle("WARNING");
alertDialogBuilder.setMessage(message);
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(which == DialogInterface.BUTTON_POSITIVE) {
if (action.equals("upload")) {
MainActivity.upload(context);
} else if (action.equals("download")) {
MainActivity.download(context);
}
} else {
dialog.cancel();
}
}
};
alertDialogBuilder.setPositiveButton("YES", listener);
alertDialogBuilder.setNegativeButton("NO", listener);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
。私はアンドロイドに新しいです。
独自のレイアウトを作成し、それをダイアログのビューとして設定することができます。それはもう少し作業とセットアップが必要ですが、それを行う方法を知っている唯一の方法です。 – zgc7009
'setView()'は、ボタンではなく、ダイアログ本体のためのものです。 –