角半径的Android对话框背景具有分层背景

时间:2014-06-13 04:25:56

标签: android android-layout

我是Android的新手,也是Java的新手。在我的应用程序中,我有一个警告对话框,我正在呕吐,显示日期和时间选择器,供用户选择他们想要发送消息的日期时间。那部分情况正常。

在我的xml中,当我设置一个背景属性(当前为蓝色并且有一个角半径)时,看起来似乎还有一个额外的白色背景,后面没有角落半径。我有点恼火。任何帮助表示赞赏。

的xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="@drawable/corners_qk"
    android:layout_width="match_parent"
    android:padding="8dp"
    android:layout_height="match_parent">

<DatePicker
    android:id="@+id/date_picker"
    android:layout_width="match_parent"
    android:calendarViewShown="true"
    android:spinnersShown="false"
    android:layout_weight="4"
    android:layout_height="0dp" />

<TimePicker
    android:id="@+id/time_picker"
    android:layout_weight="4"
    android:layout_width="match_parent"
    android:layout_height="0dp" />

<Button
    android:id="@+id/date_time_set"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:background="@drawable/corners"
    android:text="@string/picker_button"
    android:layout_height="0dp" />

</LinearLayout>

corners_qk.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners
    android:radius="5dp" />
<solid
    android:color="@color/qkblue"/>
</shape>

colors.xml:

<resources>
    <color name="red">#FF0000</color>
    <color name="qkblue">#2483d0</color>
</resources>

的java:

final View dialogView = View.inflate(this, R.layout.date_time_picker, null);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    dialogView.findViewById(R.id.date_time_set).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

             DatePicker datePicker = (DatePicker) dialogView.findViewById(R.id.date_picker);
             TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.time_picker);

             Calendar calendar = new GregorianCalendar(datePicker.getYear(),
                                datePicker.getMonth(),
                                datePicker.getDayOfMonth(),
                                timePicker.getCurrentHour(),
                                timePicker.getCurrentMinute());

             long time = calendar.getTimeInMillis();
             try {
                messageSend();
            } catch (JSONException | IOException e) {
                e.printStackTrace();
            }
        }});
    alertDialog.setView(dialogView);
    alertDialog.show();

1 个答案:

答案 0 :(得分:4)

实际上你看到的背景是default theme的{​​{1}} AlertDialog,没有办法让它透明而不是使用AlertDialog只需使用对话框你可以在哪里使其主题透明。

示例:

Light_THEME

<强>结果:

enter image description here