【问题标题】:Android - Tabs in bottom of screenAndroid - 屏幕底部的标签
【发布时间】:2016-06-25 15:13:12
【问题描述】:

我一直在寻找一种方法让我的 android 应用程序在屏幕底部有标签。

在 Android 开发者网站的样式和主题部分,他们似乎有我正在尝试做的确切示例,但是他们认为没有必要提供一个像样的示例:

我在网上找到的所有提示/解决方案都失败了。我似乎总是得到以下丑陋的布局,其中选项卡在应用程序名称旁边的屏幕顶部非常错位:-(

有没有人知道如何做到这一点?

非常感谢您提供任何提示!

【问题讨论】:

  • 那不是标签,而是一个拆分的 ActionBar。您可以在 Android 开发者指南 (developer.android.com/guide/topics/ui/actionbar.html) 中了解更多信息。
  • @Wesley,这是Split Action Bar 视图功能。你可以找到一些很好的例子。你需要在Android Manifest中定义属性。

标签: android layout tabs


【解决方案1】:

我认为这些示例对您有用:Android Bottom tab bar example AND THIS

【讨论】:

  • 虽然这在理论上可以回答问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
【解决方案2】:

【讨论】:

    【解决方案3】:

    我使用这种布局来定位屏幕底部的选项卡:

    ?xml version="1.0" encoding="utf-8"?>
    <TabHost
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>
            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:background="@drawable/bg_main_app_gradient"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
            <TabWidget
                android:id="@android:id/tabs"
                android:background="#EAE7E1"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"/>
        </LinearLayout>
    </TabHost>
    

    代码示例:https://stackoverflow.com/a/23150258/2765497

    【讨论】:

      【解决方案4】:

      我认为您没有对您的问题进行足够的搜索,因为您使用了错误的关键字进行搜索。

      您在 gmail 应用程序底部的第一张图片中显示的内容有 4 个菜单和第 5 个溢出菜单以及顶部操作栏的上方

      您可以使用清单中的简单属性在底部放置一个菜单;主要活动上的一行显示操作栏

      android:uiOptions="splitActionBarWhenNarrow"

      像这样:

      <activity
          android:name="com.example.HomeActivity"
          android:screenOrientation="portrait"
              android:uiOptions="splitActionBarWhenNarrow"
          android:theme="@style/Theme.Sherlock.Light" >
          <intent-filter>
              <action android:name="android.intent.action.MAIN" />
      
              <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
      </activity>
      

      【讨论】:

        【解决方案5】:

        Google 不建议在底部放置标签。

        请参阅以下来自 Android 的官方设计模式指南,
        并查找“不要使用底部标签栏”部分

        http://developer.android.com/design/patterns/pure-android.html

        【讨论】:

        • 不,虽然这是 Android / Google 推荐的,但对于布局设计师来说这听起来很荒谬。毕竟使用标签也不错。
        • 最新的 Google+ 应用在屏幕底部有标签,正如文档所说的不应该使用的那样。
        • 最新的 Google 应用,如 PhotoGoogle+ 使用按钮导航
        • 您所说的部分似乎已从页面中删除。
        【解决方案6】:

        我想在这里发布更新。 Bottom nav bars are now Android Canon. 主要收获是:

        1) 仅对 3-5 个图标使用底部导航栏。更少,请使用tabs。更多,请使用可滚动标签(在同一链接上向下翻页)。

        2) 避免同时使用底部导航栏和选项卡,如果这样做,请确保两者的职责明确分开。

        3) 底部导航栏应该用于导航而不是操作(使用ActionBar

        【讨论】:

          【解决方案7】:
          【解决方案8】:

          很简单....

          对于简单的标签栏,我们使用

          <?xml version="1.0" encoding="utf-8"?>
          <TabHost
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@android:id/tabhost"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
              <LinearLayout
                  android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:padding="5dp">
                  <TabWidget
                      android:id="@android:id/tabs"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content" />
                  <FrameLayout
                      android:id="@android:id/tabcontent"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:padding="5dp" />
              </LinearLayout>
          </TabHost>
          

          但在底部标签栏中我们使用

          **

          <?xml version="1.0" encoding="utf-8"?>
          <TabHost
              xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@android:id/tabhost"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
              <RelativeLayout
                  android:layout_height="fill_parent"
                  android:layout_width="fill_parent">
                  <TabWidget
                      android:id="@android:id/tabs"
                      android:layout_alignParentBottom="true"
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content" />
                  <FrameLayout
                      android:id="@android:id/tabcontent"
                      android:layout_width="fill_parent"
                      android:layout_height="fill_parent"
                      android:padding="5dp" />
              </RelativeLayout>
          </TabHost>**
          

          主要是

           android:layout_alignParentBottom=”true”;
          

          【讨论】:

            【解决方案9】:

            我遇到了你的问题,试图做同样的事情,但是根据 androids 开发指南,你不应该在底部有一个标签栏,因为这是一个 iOS 功能......

            Android Development Standards

            【讨论】:

            • 有趣的是他们自己的 Gmail 应用程序曾经在底部有菜单
            【解决方案10】:

            您似乎对底部栏有点困惑。那不是标签栏。底部栏用于操作,而不是导航屏幕。例如,在您在上面发布的 Gmail 应用程序的屏幕截图中,底部栏允许用户:撰写电子邮件、搜索、标记、刷新等。参考:http://developer.android.com/design/patterns/actionbar.html

            从技术上讲,这些按钮确实可以将用户导航到其他屏幕,但标签栏通常用于“切换”屏幕。例如按类别查看内容。

            嗯,但在最新版本的 Gmail 应用程序中,它们在顶部有这些操作按钮。叹息……

            【讨论】:

            • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
            • 感谢您的提示。该链接仅供参考。
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-02-16
            • 1970-01-01
            • 2018-02-25
            • 2015-03-08
            相关资源
            最近更新 更多