【问题标题】:Put default background of Dialog alert放置对话框警报的默认背景
【发布时间】:2013-10-19 15:33:35
【问题描述】:

在我放入 AndroidManifest.xml 之后:

<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:theme="@style/myTheme" >

在styles.xml中:

<style name="myTheme" parent="android:Theme">
<item name="android:background">@color/BG</item>
<item name="android:windowNoTitle">true</item>
</style>

每个对话框警报的背景颜色都变成了BG颜色,我怎样才能在不删除的情况下放置默认背景?

DialogInterface.OnClickListener dialogClickListener=new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
                switch(which)
                {
                    case DialogInterface.BUTTON_POSITIVE:
                        //Some code
                    break;

                    case DialogInterface.BUTTON_NEGATIVE:
                    //Some code
                    break;
                }
            }
        };

        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        builder.setMessage("Are you sure? (Reset)").setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener).show();

【问题讨论】:

  • 您可以为视图使用不同的样式吗?见stackoverflow.com/a/5134920/724068
  • @NickCaballero 我如何使用对话框构建器来做到这一点?
  • 啊,我错过了那部分。看看这个问题:stackoverflow.com/questions/2422562/…
  • @NickCaballero 谢谢,差不多了,但现在默认 DialogAlert 的样式是什么?
  • @NickCaballero 做 AlertDialog.Builder builder=new AlertDialog.Builder(new ContextThemeWrapper(this, android.R.style.Theme_Dialog)); 没用

标签: android styles android-alertdialog


【解决方案1】:

如果您有 AlertDialog 的自定义布局,请尝试以下操作:

View dialogView = View.inflate(new ContextThemeWrapper(this, android.R.style.Theme_Dialog),R.layout.dialogLayout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialogView);

【讨论】:

    猜你喜欢
    • 2013-03-09
    • 2013-01-07
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 2012-01-30
    • 2011-03-08
    • 2015-06-07
    • 2019-10-27
    相关资源
    最近更新 更多