How to change the color of Dialog box

人盡茶涼 提交于 2019-12-18 09:26:09

问题


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


回答1:


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.




回答2:


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.




回答3:


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




回答4:


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


来源:https://stackoverflow.com/questions/4386403/how-to-change-the-color-of-dialog-box

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!