如何改变对话框的颜色

发布于 2024-10-06 18:29:28 字数 76 浏览 2 评论 0原文

当我在不同的设备中安装应用程序时,对话框的颜色会更改设备到设备 我如何设置对话框的颜色

问候, 刈谷酱

When i installed my application in different devices Color of dialog box changes Devices to device
How can i set the color of Dialog box

Regards,
Kariyachan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

灯角 2024-10-13 18:29:28

您可以在 anddev.org 上找到一些线索。基本思想是扩展默认主题并在您的活动中使用它。特别是,您需要扩展 Theme.Dialog 样式。

You have some clues on anddev.org. The basic idea is to extend the default theme and use it in your activity. In particular, you will need to extend the Theme.Dialog style.

葬花如无物 2024-10-13 18:29:28

你能说出你用来测试的设备的名称吗?...可能它们可能包含自定义的 Android 版本,因此对话框颜色会发生变化。您可以保持原样,因为您的构建将使用设备可用的默认样式,否则请尝试设置样式以避免这种行为。

Can u name the devices that u r using to test?...Probably they might contain a customized Android build so the dialog color changes. You can leave it as it is since your build would use the default style available for a device else try setting styles that will avoid this behavior.

撩起发的微风 2024-10-13 18:29:28

通过设置对话框主题将活动用作对话框。然后,您可以使用自己的背景和颜色来扩展自己的布局。

Use activity as a dialog by setting dialog theme to it. Then you can inflate your own layout with your own background and colors.

皇甫轩 2024-10-13 18:29:28

使用 AlertDialog 更改 DialogBox 的颜色并执行更多操作。

你必须做什么:

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();
    }
});

Change color of DialogBox and do lot more with AlertDialog.

What you have to do:

When AlertDialog is visible on your screen, OnShowListener is called. So, by adding dialog.setOnShowListener(this) you will be able to customize your AlertDialog.

Code:

// 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();
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文