androidxmlfatal-errorandroid-tablayoutforceclose

Android - FATAL EXCEPTION: Error inflating class abLayout - Custom Style Does Not Resolve


I'm getting a fatal error stating: Binary XML file line #9: Binary XML file line #9: Error inflating class

All the research I've done points to creating a custom style to resolve the issue:

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

or perhaps the SupportLibrary - or adding a missing background:

android.view.inflateexception binary xml file line #1 error inflating class android.widget.relativeLayout

However none of those solutions seem to resolve this force close issue and I'm not sure how it can be resolved.

Any suggestions are appreciated.

ChatFrag.Java

public class ChatFrag extends Fragment {


...
    public ChatViewPagerAdapter adapter;
    private ViewPager viewPager;
    private TabLayout allTabs;
...

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        context = getActivity().getApplicationContext();
        pref = getActivity().getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
        setup = Setup.getInstance();
        isLoaded = false;
        MessagesFrag = this;


        View main = inflater.inflate(R.layout.activity_chat, container, false);

      ...
        getAllWidgets();
        setupViewPager();

        ...

           private void setupViewPager() {
        adapter = new ChatViewPagerAdapter(getActivity().getSupportFragmentManager());
        activeChats = new ActiveChats();
        visitors = new Visitors();
        adapter.addFragment(activeChats, "Active Chats");
        adapter.addFragment(visitors, "Visitors");
        setViewPageAdapter();
    }

       private void getAllWidgets() {
        viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
        viewPager.setOffscreenPageLimit(1);
        allTabs = (TabLayout) getActivity().findViewById(R.id.tabs);
    }

        private void setViewPageAdapter() {
        viewPager.setAdapter(adapter);
        allTabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if (tab.getPosition() != viewPager.getCurrentItem()) {
                    viewPager.setCurrentItem(tab.getPosition());
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {
                if (tab.getPosition() == viewPager.getCurrentItem()) {
                    adapter.notifyDataSetChanged();
                }

            }
        });
    }

activity_chat.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabGravity="fill"
        app:tabMode="fixed"
        style="@style/MyCustomTabLayout"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</LinearLayout>

LogCat

                                                                                         --------- beginning of crash
09-21 11:08:15.434 25875-25875/com.redacted.redactedmobile E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                         Process: com.redacted.redactedmobile, PID: 25875
                                                                                         android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class android.support.design.widget.TabLayout
                                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
                                                                                             at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                                                                                             at com.redacted.redactedmobile.ChatFrag.onCreateView(ChatFrag.java:84)

Build.gradle

dependencies {
  ...

    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:design:23+'
...


}

v21 styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="android:colorPrimaryDark">#227900</item>
        <item name="android:colorPrimary">#227900</item>
        <item name="colorPrimaryDark">#227900</item>
        <item name="colorPrimary">#227900</item>
        <item name="android:windowDisablePreview">true</item>
    </style>
    <style name="AppTheme.Base" parent="android:Theme.Material">
        <item name="android:colorPrimary">#3F51B5</item>
        <item name="android:colorPrimaryDark">#303F9F</item>  
        <item name="android:colorAccent">#FF4081</item>
    </style>
    <style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
        <item name="tabIndicatorColor">#FF4081</item>
    </style>
</resources>

Solution

  • you can delete that style try this instead of styling for changing tab indicator color:

    <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:tabIndicatorColor="@color/your-color-name"/>
    

    and set your color in colors...