【发布时间】:2019-11-28 04:13:26
【问题描述】:
我在以编程方式切换活动主题时遇到问题。我有一个路由器活动,它根据某些条件决定要路由的活动。并且该路由器活动可以在两次打开:应用程序启动时间与启动屏幕主题并从某处调用 startActivity 以使用 NoDisplay 或透明主题做出路由器决定。我已经在清单中设置了启动主题,它工作正常。但是在调用 startactivity 时我无法在运行时更改为透明主题。它显示黑色背景色而不是透明色。
RouterActivity:
override fun onCreate(savedInstanceState: Bundle?) {
val transparent = intent.extras?.getBoolean("Need_Transparent")?:false
if(transparent) setTheme(R.style.Theme_Transparent)
super.onCreate(savedInstanceState)
//no setContentView()
}
styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="Theme.Transparent" parent="android:Theme">
<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>
<style name="Theme.Splash" parent="android:Theme">
<item name="android:windowBackground">@android:color/holo_green_light</item>
</style>
AndroidManifest.xml:
<activity
android:name=".RouterActivity"
android:theme="@style/Theme.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
那么我怎样才能使 RouterActivity 具有两个主题:Splash(清单中的默认)和透明主题(使用其他活动的 startActivity 打开)。
【问题讨论】:
标签: android android-activity styles themes