簡體   English   中英

Android透明活動不會覆蓋整個屏幕

[英]Android Transparent Activity doesn't cover the whole screen

我一直在嘗試創建一個不透明的Activity,它與后台顯示的另一個活動重疊。

這是我的XML布局文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".EmergencyActivity">
<androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" android:background="@color/opaque_back">

        <Button
                android:text="Button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:id="@+id/button"
                app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent"
        />
    </androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>

清單文件:

      <activity
            android:name=".EmergencyActivity"
            android:theme="@style/Theme.Transparent">

樣式:

<style name="Theme.Transparent" parent="AppTheme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

屏幕圖像:

https://imgur.com/cqfBlNM - 第一個活動屏幕

https://imgur.com/NUjTAdj - 未完全顯示的活動屏幕

您的問題不夠明確,但如果您想讓活動顯示為全屏,請在活動類中嘗試:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

我通過從appCompactActivity更改為Activity來解決它,以便使用AppCompactActivity不支持的另一種樣式。

我將清單改為:

<activity
        android:name=".EmergencyActivity"
        android:launchMode="singleInstance"
        android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">

暫無
暫無

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

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