2

这是welcome_dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@drawable/dialog_background" >

<TextSwitcher
    android:id="@+id/toast_detail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"       
    android:text=""/>
</LinearLayout>

这是 dialog_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#ffffffff"
    android:endColor="#00000000"
    android:angle="45"/>
<padding android:left="20dp"
    android:top="0dp"
    android:right="20dp"
    android:bottom="0dp" />
<corners android:radius="8dp" />
</shape>

结果位于另一个我无法操作的矩形视图之上。抱歉,我不能发布结果图片,因为我还不能发布图片。

我正在尝试创建一个具有透明背景的对话倒计时计数器。我已经尝试了几种方法,但总是有额外的白色背景,我不知道那个视图来自哪里。请让我知道我做错了什么。非常感谢!

4

1 回答 1

0

在有问题的代码中,我使用了 alertDialogBu​​ilder,我认为这是有背景的视图(如果我错了,请纠正我)。我在这上面试过这条线,但它没有用:

    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));

最终,我找到了这个教程:http: //www.mkyong.com/android/android-custom-dialog-example/ 重写了我的对话框创建,瞧!我可以使用上面的代码行删除背景。

于 2013-01-31T10:18:51.643 回答