我正在尝试在主屏幕和锁定屏幕上显示透明活动。解锁后(在主屏幕中)它正确显示为透明,但在锁定屏幕上有黑色背景。我怎样才能摆脱这种黑色背景? 谢谢
样式定义:
<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>
答案 0 :(得分:0)
尽量使用半透明的 theme
来避免锁定状态下的黑屏。在您的 AndroidManifest.xml
中,在您的 android:theme="android:style/Theme.Translucent"
或 <activity
中使用 <application>
。