appcompat v21 : Materialdesign ActionBar () InflateException fehler Aufblasen Klasse

? user3871754 @ | Original: StackOverFlow

Der Versuch, in App ( appcompat v20 ), um die neue Bibliothek bewegen appcompat v21

mit: appcompat-v7:20 Arbeit schön

i done this:

ActionBarActivity implements ActionBar.TabListener, ActionBar.OnNavigationListener

and have this:

android.view.InflateException: Binary XML file line #17: Error inflating class android.support.v7.internal.widget.ActionBarOverlayLayout

http://stackoverflow.com/questions/21386077/error-inflating-class-android-support-v7-internal-widget-actionbarview



Top 5 Antwort

1Gabriele Mariotti @

Um die neue zu bedienen appcompat v21 müssen Sie :

extend the ActionBarActivity instead of FragmentActivity use getSupportActionBar() instead of getActionBar() use a theme which inherits from Theme.AppCompat.(for example Light or NoActionBar)

Auch ActionBar.TabListener, ActionBar.OnNavigationListener : Aktionsleiste Navigationsmodi sind veraltet und nicht durch Inline- Symbolleiste Aktionsleisten unterstützt. Betrachten Sie mit anderen gängigen Navigationsmuster statt .

Quelle doc:  https://developer.android.com/reference/android/support/v7/app/ActionBar.html#addTab(android.support.v7.app.ActionBar.Tab)

2Vivek Shah @

dies funktioniert Code ... copmactv7_api5 mit ... weitere Schritte sind dieselben

    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentManager;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.ViewPager;
    import android.support.v7.app.ActionBar;
    import android.support.v7.app.ActionBar.Tab;
    import android.support.v7.app.ActionBarActivity;

public class MainActivity extends ActionBarActivity implements
        ActionBar.TabListener {

AppSectionsPagerAdapter mAppSectionsPagerAdapter;
ViewPager mViewPager;

@SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.admin_main_tab);

    // Create the adapter that will return a fragment for each of the three
    // primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(
            getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener
    // for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager
            .setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
                @Override
                public void onPageSelected(int position) {
                    // When swiping between different app sections, select
                    // the corresponding tab.
                    // We can also use ActionBar.Tab#select() to do this if
                    // we have a reference to the
                    // Tab.
                    actionBar.setSelectedNavigationItem(position);
                }
            });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by
        // the adapter.
        // Also specify this Activity object, which implements the
        // TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(actionBar.newTab()
                .setText(mAppSectionsPagerAdapter.getPageTitle(i))
                .setTabListener(this));
    }
}

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the primary sections of the app.
 */
public static class AppSectionsPagerAdapter extends FragmentPagerAdapter {

    public AppSectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        switch (i) {
        case 0:
            return new AdminSettings();
        default:
            Fragment fragment = new AdminSettings();
            return fragment;
        }
    }

    @Override
    public int getCount() {
        return 3;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return "Section " + (position + 1);
    }
}

@Override
public void onTabReselected(Tab arg0,
        android.support.v4.app.FragmentTransaction arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onTabSelected(Tab tab,
        android.support.v4.app.FragmentTransaction arg1) {
    mViewPager.setCurrentItem(tab.getPosition());

}

    @Override
    public void onTabUnselected(Tab arg0,
            android.support.v4.app.FragmentTransaction arg1) {
        // TODO Auto-generated method stub

    }

}
3user3871754 @

Das Problem war, viel tiefer als es scheint.

Mein Code richtig war. Alle Ratschläge in diesem Thema relevant und korrekt.

Es stellte sich heraus, dass die externen Bibliotheken enthalten ältere Versionen support-v4, die nicht unterstützt MATERIAL DESIGN(appcompat-v7:21), sondern nur appcompat-v7:20

Es war der Grund für die ActionBar() InflateException error-inflating-class.

Update support-v4 in allen externen Bibliotheken wird das Problem lösen .

Meine build.gradle in anderen Thema:

http://stackoverflow.com/questions/26888089/multiple-dex-files-define-landroid-support-v4 .