Android 如何更改对话框的颜色
当我在不同的设备中安装我的应用程序时,对话框的颜色会随着设备的不同而变化 如何设置对话框的颜色 问候,,Android 如何更改对话框的颜色,android,user-interface,dialog,Android,User Interface,Dialog,当我在不同的设备中安装我的应用程序时,对话框的颜色会随着设备的不同而变化 如何设置对话框的颜色 问候,, Kariyachan你有一些线索。基本思想是扩展默认主题并在活动中使用它。特别是,您需要扩展Theme.Dialog样式。您有一些线索。基本思想是扩展默认主题并在活动中使用它。特别是,您需要扩展Theme.Dialog样式。您可以命名用于测试的设备吗?…它们可能包含自定义的Android版本,因此对话框颜色会发生变化。您可以保持原样,因为您的构建将使用设备可用的默认样式,否则请尝试设置可避免
Kariyachan你有一些线索。基本思想是扩展默认主题并在活动中使用它。特别是,您需要扩展Theme.Dialog样式。您有一些线索。基本思想是扩展默认主题并在活动中使用它。特别是,您需要扩展Theme.Dialog样式。您可以命名用于测试的设备吗?…它们可能包含自定义的Android版本,因此对话框颜色会发生变化。您可以保持原样,因为您的构建将使用设备可用的默认样式,否则请尝试设置可避免此行为的样式。您可以命名用于测试的设备吗?…它们可能包含自定义的Android构建,因此对话框颜色会发生变化。您可以保持原样,因为您的生成将使用设备可用的默认样式,否则请尝试设置可避免此行为的样式。通过设置对话框主题将活动用作对话框。然后,您可以使用自己的背景和颜色放大自己的布局。通过设置对话框主题将“活动”用作对话框。然后,您可以使用自己的背景和颜色放大自己的布局。更改对话框的颜色,并使用
AlertDialog
执行更多操作
你必须做的事情:
// Create AlertDialog
AlertDialog.Builder adb = new AlertDialog.Builder(context1);
adb.setTitle(context1.getString(R.string.app_name))
.setMessage(message)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = adb.create();
// Make some UI changes for AlertDialog
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
// Add or create your own background drawable for AlertDialog window
Window view = ((AlertDialog)dialog).getWindow();
view.setBackgroundDrawableResource(R.drawable.your_drawable);
// Customize POSITIVE, NEGATIVE and NEUTRAL buttons.
Button positiveButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
positiveButton.invalidate();
Button negativeButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
negativeButton.setTypeface(Typeface.DEFAULT_BOLD);
negativeButton.invalidate();
Button neutralButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEUTRAL);
neutralButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
neutralButton.setTypeface(Typeface.DEFAULT_BOLD);
neutralButton.invalidate();
}
});
当AlertDialog
在屏幕上可见时,将调用OnShowListener
。因此,通过添加dialog.setOnShowListener(this)
您将能够自定义您的AlertDialog
代码:
// Create AlertDialog
AlertDialog.Builder adb = new AlertDialog.Builder(context1);
adb.setTitle(context1.getString(R.string.app_name))
.setMessage(message)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = adb.create();
// Make some UI changes for AlertDialog
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
// Add or create your own background drawable for AlertDialog window
Window view = ((AlertDialog)dialog).getWindow();
view.setBackgroundDrawableResource(R.drawable.your_drawable);
// Customize POSITIVE, NEGATIVE and NEUTRAL buttons.
Button positiveButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
positiveButton.invalidate();
Button negativeButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
negativeButton.setTypeface(Typeface.DEFAULT_BOLD);
negativeButton.invalidate();
Button neutralButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEUTRAL);
neutralButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
neutralButton.setTypeface(Typeface.DEFAULT_BOLD);
neutralButton.invalidate();
}
});
更改对话框的颜色,并使用
AlertDialog
执行更多操作
你必须做的事情:
// Create AlertDialog
AlertDialog.Builder adb = new AlertDialog.Builder(context1);
adb.setTitle(context1.getString(R.string.app_name))
.setMessage(message)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = adb.create();
// Make some UI changes for AlertDialog
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
// Add or create your own background drawable for AlertDialog window
Window view = ((AlertDialog)dialog).getWindow();
view.setBackgroundDrawableResource(R.drawable.your_drawable);
// Customize POSITIVE, NEGATIVE and NEUTRAL buttons.
Button positiveButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
positiveButton.invalidate();
Button negativeButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
negativeButton.setTypeface(Typeface.DEFAULT_BOLD);
negativeButton.invalidate();
Button neutralButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEUTRAL);
neutralButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
neutralButton.setTypeface(Typeface.DEFAULT_BOLD);
neutralButton.invalidate();
}
});
当AlertDialog
在屏幕上可见时,将调用OnShowListener
。因此,通过添加dialog.setOnShowListener(this)
您将能够自定义您的AlertDialog
代码:
// Create AlertDialog
AlertDialog.Builder adb = new AlertDialog.Builder(context1);
adb.setTitle(context1.getString(R.string.app_name))
.setMessage(message)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = adb.create();
// Make some UI changes for AlertDialog
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(final DialogInterface dialog) {
// Add or create your own background drawable for AlertDialog window
Window view = ((AlertDialog)dialog).getWindow();
view.setBackgroundDrawableResource(R.drawable.your_drawable);
// Customize POSITIVE, NEGATIVE and NEUTRAL buttons.
Button positiveButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
positiveButton.setTypeface(Typeface.DEFAULT_BOLD);
positiveButton.invalidate();
Button negativeButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
negativeButton.setTypeface(Typeface.DEFAULT_BOLD);
negativeButton.invalidate();
Button neutralButton = ((AlertDialog)dialog).getButton(DialogInterface.BUTTON_NEUTRAL);
neutralButton.setTextColor(context1.getResources().getColor(R.color.primaryColor));
neutralButton.setTypeface(Typeface.DEFAULT_BOLD);
neutralButton.invalidate();
}
});