【问题标题】:Transparent activity on lock screen锁定屏幕上的透明活动
【发布时间】:2021-10-07 06:59:23
【问题描述】:

我正在尝试在主屏幕和锁定屏幕上显示透明活动。解锁时(在主屏幕中),它正确显示为透明,但在锁定屏幕上有黑色背景。我怎样才能摆脱这个黑色背景? 谢谢

样式定义:

    <style name="MyActivityTheme" parent="Theme.AppCompat.Light.NoActionBar" tools:ignore="NewApi">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>

清单定义:

    <application>
        <activity
            android:name=".MyActivity"
            android:windowSoftInputMode="stateVisible"
            android:theme="@style/MyActivityTheme"
            android:showOnLockScreen="true"/>
    </application>

活动布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:backgroundTint="@android:color/transparent"
    tools:context=".MyActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/holo_green_dark"
        android:text="My Activity"
        android:layout_centerInParent="true"/>
</RelativeLayout>

【问题讨论】:

    标签: android kotlin android-activity transparent lockscreen


    【解决方案1】:

    尽量使用半透明的theme,以避免在锁定状态下出现黑屏。在您的AndroidManifest.xml 中使用android:theme="android:style/Theme.Translucent" 在您的&lt;activity&lt;application&gt;

    【讨论】:

    • 我也试过这个,但没有帮助。此外,使用 AppCompatActivity 时不允许使用 Theme.Translucent,并且没有类似 Theme.AppCompat.Translucent 的 appcompant 等价物
    猜你喜欢
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    相关资源
    最近更新 更多