android材料设计标签片段没有显示出来

时间:2016-10-26 11:46:49

标签: android android-fragments material-design android-tabs

我已经关注了材料设计的Android codelabs示例,我无法获取我的片段以显示每个布局中的textedit请帮忙。这是我的MainActivity.java。任何帮助将不胜感激,我可能会告诉你,我是新手。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    setupViewPager(viewPager);

    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);
    tabs.setupWithViewPager(viewPager);

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);

    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        //supportActionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }

// Set behavior of Navigation drawer
    navigationView.setNavigationItemSelectedListener(
            new NavigationView.OnNavigationItemSelectedListener() {
                // This method will trigger on item Click of navigation menu
                @Override
                public boolean onNavigationItemSelected(MenuItem menuItem) {
                    // Set item in checked state
                    menuItem.setChecked(true);

                    // TODO: handle navigation

                    // Closing drawer on item click
                    mDrawerLayout.closeDrawers();
                    return true;
                }
            });
    /*
    tabs.addTab(tabs.newTab().setText("Dine In"));
    tabs.addTab(tabs.newTab().setText("Carry Out"));
    tabs.addTab(tabs.newTab().setText("Orders"));
    */
}

private void setupViewPager(ViewPager viewPager) {
    Adapter adapter = new Adapter(getSupportFragmentManager());
    adapter.addFragment(new DineInFragment(), "Dine In");
    adapter.addFragment(new CarryOutFragment(), "Carry Out");
    adapter.addFragment(new OrdersFragment(), "Orders");
    viewPager.setAdapter(adapter);
}

static class Adapter extends FragmentPagerAdapter {
    private final List<Fragment> mFragmentList = new ArrayList<>();
    private final List<String> mFragmentTitleList = new ArrayList<>();

    public Adapter(FragmentManager manager) {
        super(manager);
    }

    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position);
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    public void addFragment(Fragment fragment, String title) {
        mFragmentList.add(fragment);
        mFragmentTitleList.add(title);
    }

    @Override
    public CharSequence getPageTitle(int postion) {
        return mFragmentTitleList.get(postion);
    }
}

0 个答案:

没有答案