Trying to move over my stuff to use Toolbar
instead of action bar but I keep getting an error saying
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tyczj.weddingalbum/com.xxx.xxx.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
at android.support.v7.app.ActionBarActivityDelegateBase.setSupportActionBar(ActionBarActivityDelegateBase.java:165)
at android.support.v7.app.ActionBarActivity.setSupportActionBar(ActionBarActivity.java:92)
at com.xxx.xxx.MainActivity.onCreate(MainActivity.java:113)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
so then I added in my style for my activity to have no actionbar
<style name="AppCompatTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:windowActionBar">false</item>
</style>
and the theme is applies to activties in my manifest
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize|stateHidden"
android:theme="@style/AppCompatTheme" android:screenOrientation="portrait"/>
MainActivity extends GooglePlayServiceActivity so I also set the theme there too
<activity
android:name=".GooglePlayServicesActivity"
android:label="@string/title_activity_google_play_services"
android:theme="@style/AppCompatTheme">
but I still get the error. I also do not request window feature anywhere. any ideas why I still get this?
If you get the error on this line:
You need to check if your activity is referring to a theme that contains a toolbar. Your application's AppTheme might already contain a toolbar, such as
and you are trying to add a second one. If you want to use your application's AppTheme, you need to remove the theme from your activity, in the manifest.xml file.
For example:
If you are using
Appcompact
Activity use these three lines in your theme.Add single line
android:theme="@style/AppTheme.NoActionBar"
toactivity
inAndroidManifest
and you've done.AndroidManifest.xml:
styles.xml
To use Toolbar as an Action Bar, first disable the decor-provided Action Bar.
The easiest way is to have your theme extend from
(or its light variant).
Second, create a Toolbar instance, usually via your layout XML:
Then in your Activity or Fragment, set the Toolbar to act as your Action Bar:
This code worked for me.
I solved it by removing this line:
android:theme="@style/Theme.MyCompatTheme"
from activity properties in the
Manifest file