mud*_*dit 8 android android-alertdialog
我想更改Alert对话框的背景.我试过以下代码片段:
<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>
Run Code Online (Sandbox Code Playgroud)
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();
Run Code Online (Sandbox Code Playgroud)
我的应用程序显示如下对话框:

虽然我希望它看起来像:

请建议,我做错了什么.
创建对话框时使用此代码:
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)
创建自己的布局尽可能多的自定义标题,然后设置您的布局
dialog.setContentView(R.layout.yourlayout);
Run Code Online (Sandbox Code Playgroud)
注意:使用
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); before
dialog.setContentView(R.layout.yourlayout);
Run Code Online (Sandbox Code Playgroud)
否则会给出错误.