Error inflating class android.support.v7.widget.Toolbar?
Sorry Guys. I have solved this Issue long ago. I did a lot of changes. So I can't figure out which one does the trick.
I have changed the id as suggested by Jared Burrows.
Removed my support library and cleaned my project and Re added it.
Go to File -> Invalidate Caches/Restart.
Hope it works.
This is how my code looks now
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/toolbar_actionbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_actionbar">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<fragment
android:id="@+id/fragment_drawer"
android:name="com.arul.anahy.drawer.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"/>
</android.support.v4.widget.DrawerLayout>
</RelativeLayout>
toolbar_default.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
style="@style/ToolBarStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="@dimen/abc_action_bar_default_height_material"/>
ToolBarStyle
<style name="ToolBarStyle" parent="">
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Error inflating class android.support.v7.widget.Toolbar in Android Studio - Java
I solved it thanks to this post.
Error inflating class android.support.v7.widget.Toolbar?
The problem was that when I imported all the drawable files I'm using, I don't know why the fu** Android Studio decided to import them in the v-24 folder without warning me.
I moved them to the non v-24 version and it worked.
Error inflating class android.support.v7.widget.Toolbar in Android
This is what worked specifically for me. My problem had nothing to do with themes but rather the right compile versions of the dependencies and targetSdkVersion. Updated the gradle file below. Changed the
Original Gradle
compile 'com.android.support:support-v4:24.0.0-alpha2'
Changed:
compile 'com.android.support:support-v4:23.0.0'
Essentially the issue was my this version of the library did not match with the others and the minsdkversion, so something didn't mesh well. Once i updated all the dependencies (specifically from google design library) to match each other, it worked.
Error inflating class android.support.v7.widget.Toolbar. My mistake or bug?
EDIT :
Reading from another SO question.
If your activity extends AppCompactActivity
, your parent theme should be
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar" />
where as, if using ActionBarActivity
, theme should be
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar" />
I think the difference is on purpose, and not a bug. Please feel free
to correct me if i am wrong as i cannot conferm the same from anywhere
yet.
OLD :
To use Toolbar as an action bar, the first thing you need to do is disable the decor provided action bar. The easiest way is to have your theme extend from Theme.AppCompat.NoActionBar (or the light variant).
Use :
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar" />
From this post.
Related Topics
Android Facebook Sdk 3.0 Gives "Remote_App_Id Does Not Match Stored Id" While Logging In
Android: Change Shape Color in Runtime
Add Shadow to Custom Shape on Android
Debugging SQLite Database on the Device
Android Get Current Locale, Not Default
Reading SQLite File from Asset Folder
Android - How to Make Slide Menu Like Facebook, Spotify and Google +
Android Broadcast Receiver Bluetooth Events Catching
Intent.Resolveactivity Returns Null in API 30
Android Java Lang Runtimeexception Fail to Connect to Camera Service
Linkedlist Put into Intent Extra Gets Recast to Arraylist When Retrieving in Next Activity
Recyclerview Inside Scrollview Not Scrolling Smoothly
How to Clear an Imageview in Android
How to Change Text in Android Textview
Android Edittext - Finished Typing Event