自定义对话框忽略xml中的背景

时间:2013-12-09 17:59:59

标签: android dialog

我创建了一个自定义对话框,如:

    Dialog hintDialog = new Dialog(c, R.style.DialogSlideAnim);
    hintDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    hintDialog.setContentView(R.layout.hint_view_layout);

    Window window = hintDialog.getWindow();
    window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
    window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    WindowManager.LayoutParams wlp = window.getAttributes();
    wlp.gravity = Gravity.BOTTOM;

    hintDialog.show();

,它的xml就像:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hintMainLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/hint_view_bg"
android:padding="10dp" >

<TextView
    android:id="@+id/hintText"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_toRightOf="@id/hintWarningImage"
    android:ellipsize="none"
    android:gravity="center"
    android:text="(Texto)"
    android:textColor="@color/white"
    android:textSize="15sp"
    android:textStyle="bold" />

</RelativeLayout>

布局背景为:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hintViewBg" >

<corners
    android:bottomLeftRadius="0.01dp"
    android:bottomRightRadius="0.01dp"
    android:topLeftRadius="20dp"
    android:topRightRadius="20dp" />

<gradient
    android:angle="-90"
    android:endColor="@color/orange_selected"
    android:startColor="@color/orange_normal"
    android:type="linear" />

</shape>

和样式如下:

<!-- Animation for dialog box -->
<style name="DialogAnimation">
    <item name="android:windowEnterAnimation">@anim/slide_up</item>
    <item name="android:windowExitAnimation">@anim/slide_out_down</item>
</style>

<style name="DialogSlideAnim" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
</style>

它完美地工作(见图2)直到我将我的应用主题更改为“Android Action Bar Style Generator”生成的主题,现在Android忽略了我为Dialog创建的布局背景。

How it is now

How it should be (ignore the '!')

有什么想法吗?

0 个答案:

没有答案
相关问题