Error Inflating Class Android.Support.V7.Widget.Toolbar

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.

  1. I have changed the id as suggested by Jared Burrows.

  2. Removed my support library and cleaned my project and Re added it.

  3. 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



Leave a reply



Submit