本文主要是介绍Intent之后activitybar报错This Activity already has an action bar supplied by the window decor.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
解决一个app的theme在intent之后与module之后的theme兼容的问题
程序中使用intent跳转到一个新的activity,这个activity是作为module导入,强行合成的一个工程,跳转的时候闪退并且会报错
Process: com.xx.Dxxxxxxxxxx, PID: 4500java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.Dxxxxxxxxxx/com.example.xx.Dxxxxxxxxxx.activities.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3107)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3250)at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1947)at android.os.Handler.dispatchMessage(Handler.java:106)at android.os.Looper.loop(Looper.java:214)at android.app.ActivityThread.main(ActivityThread.java:7032)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.at android.support.v7.app.AppCompatDelegateImplV9.setSupportActionBar(AppCompatDelegateImplV9.java:201)at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:129)at com.example.xx.Dxxxxxxxxxx.activities.MainActivity.initToolbar(MainActivity.java:418)at com.example.xx.Dxxxxxxxxxx.ui.activities.MainActivity.initViews(MainActivity.java:309)at com.example.xx.Dxxxxxxxxxx.ui.activities.MainActivity.onCreate(MainActivity.java:174)at android.app.Activity.performCreate(Activity.java:7327)at android.app.Activity.performCreate(Activity.java:7318)at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3087)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3250) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1947) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7032) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
查看问题定位
setSupportActionBar(toolbar);
根据问题搜索到这篇文章:
https://www.cnblogs.com/hh9601/p/6404728.html
按照博主的方法把原styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"><item name="colorPrimary">@color/white</item><item name="colorPrimaryDark">@color/white</item><item name="colorAccent">@color/colorAccent</item><item name="actionOverflowMenuStyle">@style/CKMenuStyle</item></style>
改为
<style name="AppTheme.NoActivityBar""><item name="windowActionBar">false</item><item name="windowNoTitle">true</item></style>
之后不再报错,正常打开,但是界面颜色不对,等于把app的theme去掉也把module本来的主题也去掉了
想要module之后的theme和APP中的theme分离开,于是,接着把styles.xml改为:
<style name="Theme.AppCompat.Light.NoActionBar.NoActivityBar" parent="Theme.AppCompat.Light.NoActionBar"><item name="windowActionBar">false</item><item name="windowNoTitle">true</item><item name="colorPrimary">@color/white</item><item name="colorPrimaryDark">@color/white</item><item name="colorAccent">@color/colorAccent</item><item name="actionOverflowMenuStyle">@style/CKMenuStyle</item></style>
显示正确,问题解决
这篇关于Intent之后activitybar报错This Activity already has an action bar supplied by the window decor.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!