简体   繁体   English

如何在Android中自定义TabLayout?

[英]How to customize the TabLayout in android?

Here's my current tab layout: 这是我当前的标签布局:

<android.support.design.widget.TabLayout
    android:id="@+id/tab_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/pager"
    android:background="?attr/colorPrimary"
    android:elevation="6dp"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    />

which makes the screen looks like this: 这使得屏幕如下所示:

在此处输入图片说明

I want the circle-navigation (I don't know the exact term for that) so, I'm attaching a picture: 我想要圈导航(我不知道确切的用语),所以,我要附上图片:

在此处输入图片说明

As you can see, when I browse through the swipeable tabs in my screen, the circle number corresponding to the page I'm currently on should be focused (in my case, it should be dark grey, while others being light grey). 如您所见,当我浏览屏幕上的可滑动选项卡时,应将与当前当前页面相对应的圆圈编号作为焦点(在我的情况下,它应该为深灰色,而其他颜色为浅灰色)。 You can see the circles at the bottom of the page. 您可以在页面底部看到圆圈。

I know I can make those circles part of the fragment and then make the respective circle focused, but then, with every swipe, the set of circles would also get swiped - which I don't want. 我知道我可以使这些圆成为片段的一部分,然后使各个圆集中,但是随后,每次滑动,该组圆也将被滑动-这是我不希望的。

Is there a way to achieve that? 有办法实现吗?

You can achieve this by using viewpager. 您可以使用viewpager来实现。 Most common viewpager indicator is http://viewpagerindicator.com/ by Jakewharton. 最常见的viewpager指示器是Jakewharton的http://viewpagerindicator.com/ Its also compatible with the ViewPager from the Android Support Library 它还与Android支持库中的ViewPager兼容

using with studio 与工作室一起使用

Add this to your source repositories after you declare your plugins: 声明插件后,将其添加到源存储库中:

repositories {
    maven { url "http://dl.bintray.com/populov/maven" }
    mavenCentral()
}

And in the module's build.gradle file add the dependency 并在模块的build.gradle文件中添加依赖项

dependencies {
   // ...
   compile 'com.viewpagerindicator:library:2.4.1'
   // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM