使用抽屉和报亭中的标签导航

时间:2014-04-07 15:03:05

标签: android android-actionbar actionbarsherlock

我正在尝试复制Google newstand app导航系统,我可以同时使用导航抽屉菜单和标签,如下所示: enter image description here

我正在尝试实现与newstand完全相同的效果,操作栏和标签的单色,以及不跨越整个屏幕长度的标签 我能够反编译应用程序,我已经看到了另一个使用此应用程序的应用程序(系列指南)的来源,但它们非常复杂,我无法找到并找出它的实现位置和方式。

我尝试使用Android Studio为我创建的模板用于导航抽屉并添加标签但没有效果

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

        mNavigationDrawerFragment = (NavigationDrawerFragment)
                getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
        mTitle = getTitle();

        // Set up the drawer.
        mNavigationDrawerFragment.setUp(
                R.id.navigation_drawer,
                (DrawerLayout) findViewById(R.id.drawer_layout));

        ActionBar actionBar = getSupportActionBar();
        /*
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowTitleEnabled(true);


        ActionBar.Tab tab = actionBar.newTab()
                .setText("Artist")
                .setTabListener(new TabListener<PlaceholderFragment>(
                        this, "artist", PlaceholderFragment.class));
        actionBar.addTab(tab);

        tab = actionBar.newTab()
                .setText("album")
                .setTabListener(new TabListener<PlaceholderFragment>(
                        this, "album", PlaceholderFragment.class));
        actionBar.addTab(tab);
*/

        actionBar.setHomeButtonEnabled(true);
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        String[] tabs = { "Top Rated", "Games", "Movies" };
        // Adding Tabs
        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(new TabListener<PlaceholderFragment>(
                            this, "album", PlaceholderFragment.class)));
        }
    }

到目前为止,我已尝试使用android库,但我不介意使用外部onex,如actionbar sherlock

1 个答案:

答案 0 :(得分:3)

You're looking for Google's SlidingTabLayoutSeriesGuide是开源的,但使用PagerSlidingTabStrip

要使用Google的SlidingTabLayout,您需要将两个班级复制到您的项目中。您需要的课程是:

实现SlidingTabLayout的示例布局如下所示:

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

    <your_path_to.SlidingTabLayout
          android:id="@+id/slidingTabs"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
          android:id="@+id/viewPager"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_weight="1" />

</LinearLayout> 

使用SlidingTabLayout对布局进行充气并初始化View.findViewById后,请致电SlidingTabLayout.setViewPagerViewPager绑定到标签页。

Check out Google's example for a full project

相关问题