开发者

Setting the "dim" color for a Dialog

I understand how to set the dim amount for a Dialog. However, I would prefer that the color was a translucent whit开发者_开发知识库e instead of a translucent black (or is it dark gray?). Any ideas?


First, you need to create white 9-patch drawable. Similar to panel_background.9.png drawable (which is black) that can be found at path:

 <android-sdk-dir>/platforms/android-#/data/res/drawable-hdpi/panel_background.9.png

Let's assume your drawable will be called white_panel_background.9.png.


Option 1.

You can create your custom theme that extends Theme.Dialog and overrides windowBackground attribute with custom white 9-patch drawable.

 <style name="Theme.WhiteDialog" parent="@android:style/Theme.Dialog">
     <item name="android:windowBackground">@drawable/white_panel_background</item>  
 </style>

And then use this theme in your dialog:

Dialog dialog = Dialog(context, R.style.Theme_WhiteDialog);

Option 2.

If you've already created the dialog (with default theme), you still can update its window background:

Dialog dialog = ...;
...
Resources res = getResources();
Drawable drawable = res.getDrawable(R.drawable.white_panel_background);
dialog.getWindow().setBackgroundDrawable(drawable);

Note: you'll need to change text colors from white to black (so its visible on white background).
Note: you'll need to do some extra steps for AlertDialog as it uses its own styles for backgrounds. For more details see AlertDialog style.


Setting the "dim" color for a Dialog

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜