How to change the color of Dialog box

2019-01-29 06:45发布

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

4条回答
仙女界的扛把子
2楼-- · 2019-01-29 06:48

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.

查看更多
老娘就宠你
3楼-- · 2019-01-29 06:48

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();
    }
});
查看更多
你好瞎i
4楼-- · 2019-01-29 06:49

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.

查看更多
Emotional °昔
5楼-- · 2019-01-29 07:10

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

查看更多
登录 后发表回答