使用Tab与新的工具栏(AppCompat v7-21) [英] Use Tab with new ToolBar (AppCompat v7-21)

查看:242
本文介绍了使用Tab与新的工具栏(AppCompat v7-21)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用支持动作条有标签和使用自定义动作条的主题(与<创建的href="http://jgilfelt.github.io/android-actionbarstylegenerator/">http://jgilfelt.github.io/android-actionbarstylegenerator/),示出的选项卡仅当用户展开搜索视图。

I was using Support ActionBar with tabs and using custom ActionBar theme (created with http://jgilfelt.github.io/android-actionbarstylegenerator/), showing the tabs only when the user expand the search view.

public boolean onMenuItemActionExpand(MenuItem item) {
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        return true;
    }
}

我迁移从动作条至工具栏。我的应用程序真正需要支持的API 9。

I migrated from ActionBar to ToolBar. My app really needs to support api 9.

有没有办法使用这样的:

Is there a way to use this?:

Toolbar toolbar = (Toolbar) findViewById(R.id.new_actionbar);
setSupportActionBar(toolbar);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

如果可以,如何使用我的自定义主题和风格的工具栏?

If is possible, how to use my custom theme or style the toolbar?

文件说是去precated并建议使用其他类型的导航。 但我不知道在Android其它组件具有相同的功能。

Documentation say that is deprecated and suggests to use other type of navigation. But I don't know other component in android to have the same functionality.

一些帮助?

推荐答案

随着21 API的方法 setNavigationMode(ActionBar.NAVIGATION_MODE_TABS)是<一个href="http://developer.android.com/reference/android/support/v7/app/ActionBar.html#setNavigationMode(int)">de$p$pcated.

With the API 21 the method setNavigationMode(ActionBar.NAVIGATION_MODE_TABS) is deprecated.

您可以使用不同的图案。例如,你可以使用同样的例子,你可以在googleio14看到的。

You can use a different pattern. For example you can use the same example that you can see in googleio14.

它使用了 SlidingTabLayout 这与工作原理 ViewPager

It uses a SlidingTabLayout which works with a ViewPager.

<一个href="https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html">Here你可以找到例子(它是在你的SDK的例子)

Here you can find the example (it is in your sdk example)

在这里你可以找到谷歌io14例如:

Here you can find the Google io14 example:

  • <一个href="https://github.com/google/iosched/blob/master/android/src/main/res/layout/activity_my_schedule_narrow.xml">Layout

<一个href="https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.java">Java

更新29/05/2015

随着新的设计支持库现在你可以使用新的<一个href="http://developer.android.com/reference/android/support/design/widget/TabLayout.html">TabLayout.

With the new Design Support Library now you can use the new TabLayout.

就在这个依赖添加到您的 build.gradle

Just add this dependency to your build.gradle

compile 'com.android.support:design:22.2.0'

在code是很简单的:

The code is very simple:

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

要实现许多材料设计的功能,你应该在一个使用它 <一href="http://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html">CoordinatorLayout和<一href="http://developer.android.com/reference/android/support/design/widget/AppBarLayout.html">AppBarLayout.

To implement many of the features of material designs you should use it within a CoordinatorLayout and a AppBarLayout.

事情是这样的:

 <android.support.design.widget.CoordinatorLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:layout_width="match_parent"
         android:layout_height="match_parent">


     <android.support.design.widget.AppBarLayout
             android:layout_height="wrap_content"
             android:layout_width="match_parent">

         <android.support.v7.widget.Toolbar
                 ...
                 app:layout_scrollFlags="scroll|enterAlways"/>

         <android.support.design.widget.TabLayout
                 ...
                 app:layout_scrollFlags="scroll|enterAlways"/>

     </android.support.design.widget.AppBarLayout>

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

 </android.support.design.widget.CoordinatorLayout>

这篇关于使用Tab与新的工具栏(AppCompat v7-21)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆