2012-04-27 102 views
2

对话框布局的xml:安卓:更改自定义AlertDialog背景

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/root_view" 
    android:padding="3dp" 
    android:background="@android:color/white" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 

    //...content... 

</TableLayout> 
上图钉挖掘时,在地图覆盖

对话框实现:

AlertDialog.Builder builder; 

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Service.LAYOUT_INFLATER_SERVICE); 
View layout = inflater.inflate(R.layout.map_kap_dialog, 
        (ViewGroup) mapView.findViewById(R.id.root_view)); 

//prepare info to show... 
//info prepared 

//other preparations stuff 
builder = new AlertDialog.Builder(context); 
builder.setView(layout); 
dialog = builder.create(); 
dialog.setInverseBackgroundForced(true); 
dialog.setCanceledOnTouchOutside(true); 
//show it 
dialog.show(); 

,我看到的,当测试:

enter image description here

所以我想围绕对话框的浅灰色背景(围绕s quare白色空间)变成白色,所以它不会看起来很丑。谁能帮我?

回答

1

嘿设置你的视图建设者创建这条灰色的线在上下,而不是你可以setView到你的dialog.like dialog.setView(layout,0,0,0,0);它会将你的布局绑定到整体对话。

9

我有同样的问题,我设法使用自定义对话框这样来解决它:

public class CustomDialog extends Dialog { 
    public CustomDialog(Context context, View view) { 
     super(context); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(view); 
     getWindow().getDecorView().setBackgroundResource(android.R.color.transparent); 
    } 
} 
0

另一种选择是从布局中删除android:background="@android:color/white"。然后警报对话框的默认浅灰色背景统一。 (因为你在黑暗的主题上被迫反过来)至少它看起来不错,值得一提。只是我的两分钱。