现在的位置: 首页 > 移动开发 > 正文

android 5.0 toolbar 上实现 material tabs

2019年09月09日 移动开发 ⁄ 共 2063字 ⁄ 字号 评论关闭
文章目录

android5.0 中如何才能实现类似play store中的tab效果?(滚动式隐藏,合适的间距),我尝试过 SlidingTabs 和其他的一些lib库,他们基本上都超期了..
 
关于一些细节方面,android5之前的版本中,api20一下,我经常使用 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ,但是在android5.0中,整个ActionBar  都被ToolBar替换了
.
如何才能正确的使用 Material Design 做出类似 google paly store的效果? android 5中如何让tabs在滚动的时候隐藏?

处理方法

他们的layout如下,基本上是这样的,达不到和 play store完美一样的程序

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
 
    <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/my_awesome_toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.ActionBar">
 
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
 
            <TextView
                android:text="@string/hello_world"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="16dp"
                style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" />
 
            <widget.SlidingTabLayout
                android:id="@+id/sliding_tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>
    </android.support.v7.widget.Toolbar>
 
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin">
 
        <TextView
            android:text="@string/hello_world"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
 
        <android.support.v4.view.ViewPager
            android:id="@+id/ViewPager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
 
    </LinearLayout>
</LinearLayout>

原文地址:http://www.itmmd.com/201411/209.html 
该文章由 萌萌的IT人 整理发布,转载须标明出处。

抱歉!评论已关闭.