Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Iappcompat v21:材质设计操作栏()充气异常错误充气类_Android_Nullpointerexception_Android Actionbar_Fragment_Android Appcompat - Fatal编程技术网

Android Iappcompat v21:材质设计操作栏()充气异常错误充气类

Android Iappcompat v21:材质设计操作栏()充气异常错误充气类,android,nullpointerexception,android-actionbar,fragment,android-appcompat,Android,Nullpointerexception,Android Actionbar,Fragment,Android Appcompat,正在尝试将appcompat v20中生成的应用程序移动到新库appcompat v21 使用:appcompat-v7:20工作正常 我这样做: ActionBarActivity implements ActionBar.TabListener, ActionBar.OnNavigationListener 并有以下几点: android.view.InflateException:二进制XML文件第17行:膨胀类android.support.v7.internal.widget.Act

正在尝试将appcompat v20中生成的应用程序移动到新库appcompat v21

使用:appcompat-v7:20工作正常

我这样做:

ActionBarActivity implements ActionBar.TabListener, ActionBar.OnNavigationListener
并有以下几点:

android.view.InflateException:二进制XML文件第17行:膨胀类android.support.v7.internal.widget.ActionBarOverlayLayout时出错

要使用新的appcompat v21,您必须:

扩展ActionBarActivity而不是FragmentActivity 使用getSupportActionBar而不是getActionBar 使用从theme.AppCompat.com继承的主题,例如Light或NoActionBar 编辑:23/04/2015

对于新的appcompat v22.1,您应该使用新的AppCompatActivity而不是ActionBarActivity

此外,ActionBar.TablListener、ActionBar.OnNavigationListener:Action bar导航模式已被弃用,内联工具栏操作栏不支持这些模式。请考虑使用其他常见导航模式。

来源文件: 要使用新的appcompat v21,您必须:

扩展ActionBarActivity而不是FragmentActivity 使用getSupportActionBar而不是getActionBar 使用从theme.AppCompat.com继承的主题,例如Light或NoActionBar 编辑:23/04/2015

对于新的appcompat v22.1,您应该使用新的AppCompatActivity而不是ActionBarActivity

此外,ActionBar.TablListener、ActionBar.OnNavigationListener:Action bar导航模式已被弃用,内联工具栏操作栏不支持这些模式。请考虑使用其他常见导航模式。

来源文件:

这是工作代码…copmactv7_api5使用…其他步骤相同

    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

    }

}

这是工作代码…copmactv7_api5使用…其他步骤相同

    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

    }

}

这个问题比看起来要深刻得多

我的代码是正确的。本主题中的所有建议都是相关且正确的

事实证明,外部库包含旧版本的support-v4,它不支持材料DESIGNappcompat-v7:21,只支持appcompat-v7:20

这就是ActionBar充气异常错误充气类的原因

在所有外部库中更新support-v4将解决此问题

其他主题中的My build.gradle:


.

这个问题比看起来要严重得多

我的代码是正确的。本主题中的所有建议都是相关且正确的

事实证明,外部库包含旧版本的support-v4,它不支持材料DESIGNappcompat-v7:21,只支持appcompat-v7:20

这就是ActionBar充气异常错误充气类的原因

在所有外部库中更新support-v4将解决此问题

其他主题中的My build.gradle:


.

@user3871754使用工具栏发布布局对不起,错误消息,请在“我的所有源代码”中再次检查我的回答异常:这也可能有助于解决此问题:既然在v22上不推荐使用ActionBarActivity,您应该使用AppCompatActivityinstead@user3871754发布带有工具栏的布局抱歉错误消息,在我的所有源代码中再次检查我的答案异常:这可能也有助于解决此问题:既然在v22上不推荐使用ActionBarActivity,您应该使用AppCompatActivity,而不是使用R.id.pager中的内容?你的呼机里有什么?