Thursday 1 October 2015

Error:Error inflating class android.support.design.widget.TabLayout

While creating tab layout in version higher than api level 21 in android, Sometime we get the error

Error inflating class android.support.design.widget.TabLayout.

The Reason is that tab layout widget provided by android design library need a style attribute for that tab layout. Basically it needs a indicator color for that tab layout. Suppose this is your tab layout file.



In above file, You have a tab layout widget. But you haven't specified the style attribute for that.


For using material design theme you have to add a new styles.xml file in res folder. But first you need to add a folder values-v21 in app/res folder for using material design. Then create an xml file named styles.xml in that values-v21 folder. Add following code in that file.



Now add the style "MyCustomTabLayout" attribute in your viewpager or tab layout file.



Now build the project again and run. You will not get that error now.

I hope it helps. If you like the post share , like and comment. If you have any other doubt comment.
For more post like this subscribe to right of the webpage.
Like my facebook page : https://www.facebook.com/geeksmember?fref=ts&ref=br_tf

8 comments:

  1. Thank you, your solution worked like charm.

    ReplyDelete
  2. No Resource found(Widget.Design.TabLayout) error

    ReplyDelete
    Replies
    1. Have you added the dependency for design support library provided by google in your build.gradle file ??

      like:

      dependency{
      compile 'com.android.support:design:22.2.0';
      }

      Delete
  3. Hello,
    This solution doesn't work for me for some reason.. I've done everything it says here , but keep getting the same crash (error inflating TabLayout)

    ReplyDelete
  4. This solution also doesn't work for me please give any other solution .... Thanks

    ReplyDelete
  5. It does not work for us as well. Please let us know what more could be done

    ReplyDelete
  6. Didn't worked for me in 4.4 versions

    ReplyDelete

Related Posts

Related Posts Plugin for WordPress, Blogger...