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
There are two simple and quick solutions
go to res-->values-->styles
YOU can also watch this video for more easiness CLICK HERE
Solution 1:
You can remove the action bar by replacing
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Solution2:
Simply add these lines
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
So now your style file look like this
`
<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>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
`
Just put parent="Theme.AppCompat.NoActionBar"
in your style.xml file
Like - <style parent="Theme.AppCompat.NoActionBar" name="AppTheme.NoActionBar">
This is how I solved the problem. Add below code in your AndroidMainfest.xml
<activity android:name=".YourClass"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
</activity>
Add this in your values/styles.xml
<style name="YourCustomTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
<style name="AppBaseTheme" parent="YourCustomTheme">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
And add the following code in your values-v11/styles.xml and values-v14/styles.xml
<style name="AppBaseTheme" parent="YourCustomTheme">
</style>
Thats it. It will work.
If you get the error on this line:
setSupportActionBar(...);
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
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
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:
<activity
android:name=".ui.activities.SettingsActivity"
android:theme="@style/AppTheme1" /> --> remove this theme
You need to change
<activity
android:name=".YOUR ACTIVITY"
android:theme="@style/AppTheme.NoActionBar" />
</application>`
these lines in the manifest.It will perfectly work for me.