我在Api 8模拟器中看到黑色背景,如何删除它?
这是对话框创建代码
LayoutInflater inflater = getLayoutInflater();
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
//Dialog alert = new Dialog(this, android.R.style.Theme_Light_Panel);
// Build the dialog
AlertDialog.Builder alert = new AlertDialog.Builder(this);
//alert.setContentView(inflater.inflate(R.layout.dialoglayout, null));
alert.setView(inflater.inflate(R.layout.dialoglayout, null));
alert.setTitle("Testing title");
alert.setIcon(R.drawable.ic_launcher);
alert.setCancelable(false);
alert.show();
这是对话框的外观
我的布局代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/WHITE" >
<ScrollView
android:id = "@+id/id_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/WHITE" >
<View
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:id="@+id/id_prim_separator"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="4dp"
android:background="@color/GRAY"/>
<TextView
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop ="8dp"
android:textColor="@color/BLUE"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/id_prim_separator"
android:textStyle="bold"
android:id="@+id/ID_title"
android:textSize="22sp"
android:focusable="true"
android:text="This is sample Title"
/>
<TextView
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:textSize="15sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/ID_snooze_task_description"
android:layout_below="@+id/ID_title"
android:focusable="true"
android:textColor="@color/DARKGRAY"
android:text="This is sample description"
/>
<View
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="@+id/ID_snooze_task_description"
android:id="@+id/id_details_separator"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_marginTop="4dp"
android:background="@color/GRAY"/>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:id="@+id/id_preview_button"
android:layout_below="@+id/id_scroll_view"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id = "@+id/id_edit_btn"
android:text="Edit"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id = "@+id/id_ok_btn"
android:text="Ok"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id = "@+id/id_cancel_btn"
android:text="Cancel"
/>
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:2)
我认为您应该使用AlertDialog
或取决于您的应用程序层次结构Dialog
,而不是使用DialogFragment
。使用Dialog
,您可以获得如下所需的结果:
Dialog alert = new Dialog(MyAcivity.this, android.R.style.Theme_Light_Panel);
alert.requestWindowFeature(Window.FEATURE_NO_TITLE);
alert.setContentView(getLayoutInflater().inflate(R.layout.my_dialog, null));
alert.show();