我想要实现的是具有类似对话框透明度的活动,并具有 100% 的相对布局内容可见性。 这是活动的 xml: 这是显而易见的: 现在背景仍然可见,我做错了什么? --- 编辑:我添加了 到线性布局。 现在背景是我想要的透明,而且RelativeLayout 中的TextViews 也是透 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我一直在解决这个特定问题。 每当我加载上一个活动的当前活动(在顶部)时,它都会导致加载活动的背景(具有透明背景)变黑。
我可以在加载过渡时看到透明设置,但是当它完全加载时它会变成黑色。
这是我用来使背景透明的代码:
window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
上面的代码在另一个视图上的其他地方就像这个一样。 两个视图上的所有设置都相同,但这个视图不希望正常工作。
这是活动的代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:scaleType="fitCenter"
tools:context=".ui.activities.TourConnectActivity">
<ImageView
android:id="@+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="24dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="24dp"
android:background="@drawable/rounded_top"
android:contentDescription="background"
android:scaleType="centerCrop"
android:src="@drawable/launch_bg"
app:layout_constraintBottom_toTopOf="@+id/view7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<View
android:id="@+id/view7"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:background="@drawable/preview_green_border_top"
app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/backgroundImage" />
<ImageView
android:id="@+id/logo"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="128dp"
android:layout_marginEnd="128dp"
android:background="@drawable/org_logo_border"
android:contentDescription="background"
android:cropToPadding="true"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/view7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="@drawable/dot"
tools:ignore="HardcodedText" />
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="315dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="64dp"
android:background="@drawable/rounded_bottom"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/view7">
<TextView
android:id="@+id/connectTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="This tour is presented by"
android:textColor="#333"
android:textSize="12sp"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/connectSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/roboto"
android:text="Jackson Hole Land Trust"
android:textAlignment="center"
android:textColor="@color/colorTSGGreen"
android:textSize="20sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="175dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:background="@color/transparent">
<TextView
android:id="@+id/connectMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:text="@string/lorem_ipsum_3"
android:textColor="#333"
android:textSize="16sp" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/learnMore"
style="@style/Widget.MaterialComponents.Button.Icon"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableStart="@drawable/ic_none"
android:drawableEnd="@drawable/ic_exit_to_app"
android:onClick="buttonClick"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/learn_more"
android:textColor="@color/loginTextColor"
android:textSize="18sp"
app:backgroundTint="@color/colorTSGGreen" />
</LinearLayout>
<ImageView
android:id="@+id/buttonBack"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
android:contentDescription="close button"
android:onClick="iconClick"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close" />
</androidx.constraintlayout.widget.ConstraintLayout>
我倾向于认为它与上一个活动的地图视图有关,但我不确定可能是这样。
任何输入将不胜感激。 谢谢。
比以编程方式设置透明背景更好的方法是更改其样式。 特别是当背景在其他情况下保持不变时。 查看此问题及其评分最高的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.