android - 如何将tablayout的指示器从底部更改为顶部?

标签 android android-layout android-fragments android-intent android-activity

我想将 tablayout 的指示器从底部更改为顶部。

我的代码

activity_tab.xml

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

    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"

        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        app:tabIndicatorColor="#000000"

        app:tabMode="scrollable"
        />
</android.support.design.widget.AppBarLayout>

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

我想要这个结果。

enter image description here

怎么做

谢谢你问我,抱歉英语不好。

最佳答案

不要使用 scale = -1 之类的东西。

从 XML 您可以使用 app:tabIndicatorGravity="top"

从代码中您可以使用 setSelectedTabIndicatorGravity(INDICATOR_GRAVITY_TOP)

关于android - 如何将tablayout的指示器从底部更改为顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33810156/

相关文章:

android - AppWidget 在模拟器和手机上看起来不同 - 移动查看内容

android - 在 ViewPager 中,滑动到第 3 个选项卡时,tab1 中的子 fragment 消失

java - OnClickListener 不适用于谷歌地图 fragment 顶部的按钮

android - 如何从资源中将值加载到数组列表中

java - 如何在 Android 上访问 API 17 的联系人

android - Robolectric 示例和 Gradle 插件

java - 从 switch case 获取返回值到函数或方法

javascript - 使用 appcelerator titan 在 android 上进行多个预定的 android 通知

android - 如何在 textView 中生成数学常数 e(如 exp(1))?

java - Android,强制onLayoutChange函数在分配后执行一次?