微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

锁定屏幕上的透明活动

如何解决锁定屏幕上的透明活动

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

样式定义:

    <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>

解决方法

尽量使用半透明的 theme 来避免锁定状态下的黑屏。在您的 AndroidManifest.xml 中,在您的 android:theme="android:style/Theme.Translucent"<activity 中使用 <application>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。