【问题标题】:How to create tabs inside Action Bar?如何在操作栏中创建选项卡?
【发布时间】:2016-05-08 21:03:21
【问题描述】:

如图所示

是否可以在ActionBar 中创建标签?

我只设法创建了TabHost,但它位于ActionBar 之下,而不是在其中(我认为标签在内部是很明显的,因为从ActionBar 标题到标签之间有完美的流程)。

【问题讨论】:

  • 分享你尝试的代码
  • 图片中的那些标签不在ActionBar中,它们在ActionBar

标签: android android-tabs


【解决方案1】:

正如@Rami 所说:

您图片中的那些选项卡不在操作栏中,它们在 操作栏

您可以将它与TabLayout(来自支持库)或其他库一起使用。TabLayout 是最好的选择。

这里有一个很好的教程:https://guides.codepath.com/android/google-play-style-tabs-using-tablayout

也请检查此链接:How to implement android TabLayout design support libarary with Swipe views

示例:

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    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:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways" />

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

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

看一看:Tabs in TabLayout not filling up entire ActionBar

【讨论】:

    【解决方案2】:

    根据图片,选项卡不在操作栏内,但选项卡颜色和操作栏颜色相同,这就是它看起来像的原因

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多