Custom Dialog ignoring the background in xml

纵然是瞬间 提交于 2019-12-11 19:41:32

问题


I created a custom Dialog like:

    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();

and its xml is like:

<?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>

With its layout background being:

<?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>

and the style like:

<!-- 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>

And it worked perfectly (see image bellow) until before i changed my app Theme to the one generated by the "Android Action Bar Style Generator" and now Android is ignoring the layout background i created for the Dialog.

Any thoughts?

来源:https://stackoverflow.com/questions/20477412/custom-dialog-ignoring-the-background-in-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!