簡體   English   中英

如何使 android 中的對話框背景透明?

[英]How can I make the background of my dialog in android transparent?

我正在嘗試使對話框中的背景透明。 我希望進度條顯示在我的活動前面。 不幸的是,背景始終保持白色。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/loading_cont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:backgroundTint="#00000000"
android:background="@android:color/transparent"
>

<RelativeLayout
    android:id="@+id/loading_dialog_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:backgroundTint="#00000000"
    android:background="@android:color/transparent"
    >

    <ProgressBar
        android:id="@+id/login_progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true" >
    </ProgressBar>

</RelativeLayout>

創建一個名為transparent.xml的新Drawable Resource file

透明的。xml

<shape 
      android:shape="rectangle"
      xmlns:android="http://schemas.android.com/apk/res/android">
</shape>

現在設置android:background="@drawable/transparent"

在初始化對話框的位置添加此代碼

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);

或者您也可以添加此代碼

 dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM