解決一個app的theme在intent之後與module之後的theme兼容的問題
程序中使用intent跳轉到一個新的activity,這個activity是作爲module導入,強行合成的一個工程,跳轉的時候閃退並且會報錯
Process: com.xx.Dxxxxxxxxxx, PID: 4500
java.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>
顯示正確,問題解決