如何在对话框中删除白色边框?

时间:2012-02-25 21:13:58

标签: android dialog

我读了很多主题,但我没有找到问题的答案。我正在尝试将android.R.style.Theme_Translucent_NoTitleBar或xml样式与

一起使用
<style name="CustomDialogTheme" parent="@android:style/Theme.Dialog">
        <item name="android:windowBackground">@color/transparent_white</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>

即使我已添加

dialog.getWindow().setBackgroundDrawableResource(R.drawable.pixel);

像素是透明可绘的,但没有运气。我总是有白色边框。

我的代码如下:

Dialog dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.getWindow().setBackgroundDrawableResource(R.drawable.pixel);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
ListView modeList = new ListView(this);
String[] stringArray = new String[] { "aaa", "bbb" };
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,
stringArray);
modeList.setAdapter(modeAdapter);
builder.setView(modeList);
dialog = builder.create();

此致 Swierzy

1 个答案:

答案 0 :(得分:2)

对话框的白色边框是9patch图像 你的背景图片必须是9patch图片。 http://developer.android.com/guide/developing/tools/draw9patch.html

你可以自己画画并在那里制作你喜欢的任何边框。 你可以像那样创建对话

public AboutDialog(Context context) {
    super(context,R.style.Theme_Dialog);
   .......

和你的风格,例如


<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme" parent="android:Theme">
</style>
<style name="Theme.Dialog" parent="Theme">
    <item name="android:layout_width">wrap_content</item>

    <item name="android:layout_height">wrap_content</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowNoTitle">true</item>

    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@drawable/bg</item> <------- your 9patch background picture
</style>

希望这有助于升技

相关问题