更改弹出对话框的背景颜色 [英] Change the background color of a pop-up dialog

查看:770
本文介绍了更改弹出对话框的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的Andr​​oid code,显示了弹出对话框,但我想从黑色改变背景颜色为白色,然后在写作的颜色。

这是对话的code:

 米preFS = preferenceManager.getDefaultShared preferences(本);

    布尔welcomeScreenShown = M prefs.getBoolean(welcomeScreenShown preF,假);

    如果(!welcomeScreenShown){


        字符串whatsNewText = getResources()的getString(R.string.Text)。
        新AlertDialog.Builder(本).setMessage(whatsNewText).setPositiveButton(
                R.string.ok,新DialogInterface.OnClickListener(){
            公共无效的onClick(DialogInterface对话,诠释它){
                dialog.dismiss();
            }
        })。显示();
        共享preferences.Editor编辑= M prefs.edit();
        editor.putBoolean(welcomeScreenShown preF,真正的);
        editor.commit(); //非常重要,保存preference
    }
 

解决方案

如果你只是想要一个光的主题,并且不拘泥于特定的颜色,那么你可以通过一个主题ID到AlertDialog.Builder构造。

  AlertDialog.Builder(这一点,AlertDialog.THEME_HOLO_LIGHT)...
 

  AlertDialog.Builder(这一点,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)...
 

I wrote android code that shows a pop-up dialog but I want to change the background color from black to white , and then the color of the writing.

This is the dialog's code:

mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref, false);

    if (!welcomeScreenShown) {


        String whatsNewText = getResources().getString(R.string.Text);
        new AlertDialog.Builder(this).setMessage(whatsNewText).setPositiveButton(
                R.string.ok, new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).show();
        SharedPreferences.Editor editor = mPrefs.edit();
        editor.putBoolean(welcomeScreenShownPref, true);
        editor.commit(); // Very important to save the preference
    }

解决方案

If you just want a light theme and aren't particular about the specific color, then you can pass a theme id to the AlertDialog.Builder constructor.

AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT)...

or

AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT)...

这篇关于更改弹出对话框的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆