我想更改“警报”对话框的背景。我尝试过以下代码:
<style name="Theme.AlertDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:background">@android:color/transparent</item>
<item name="android:textColor">#659F26</item>
<item name="android:windowTitleStyle">@style/Theme.AlertDialog.Title</item>
</style>
<style name="Theme.AlertDialog.Title" parent="@android:style/TextAppearance.DialogWindowTitle">
<item name="android:background">@drawable/cab_background_top_example</item>
</style>
Java代码:
ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.Theme_AlertDialog);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctw);
alertDialogBuilder.setTitle(getResources().getString(R.string.confirmation));
alertDialogBuilder.setMessage(getResources().getString(R.string.msg));
alertDialogBuilder.show();
我的应用正在显示如下对话框:
虽然我希望它看起来像:
请建议,我做错了什么。
答案 0 :(得分:6)
创建对话框时使用此代码:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
创建自己的布局尽可能多地使用标题进行自定义,然后设置布局
dialog.setContentView(R.layout.yourlayout);
注意:使用
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); before
dialog.setContentView(R.layout.yourlayout);
否则会出错。
答案 1 :(得分:0)
ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.Theme_AlertDialog);
在此行中使用而不是&#34; this
&#34;使用ActivityName.this