Android - iphone 风格的 tabhost

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2677698/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:52:56  来源:igfitidea点击:

Android - iphone style tabhost

androidtabsandroid-tabhostandroid-style-tabhost

提问by Soni Ali

Is it possible to style the Android Tabhost to look like that of the iPhone? If not, is there any open source code that can show how to create Bottom Tabs for Android ?

是否可以将 Android Tabhost 设计为看起来像 iPhone 的样式?如果没有,是否有任何开源代码可以展示如何为 Android 创建底部标签?

alt text
(source: appshopper.com)
alt text

替代文字
(来源:appshopper.com
替代文字

回答by Adil Soomro

I would suggest you guys to not change the default look and feel of the tabs, because users on android devices have their own user experience, and you will negate that past experience, so don't force them to learn new tabs experience (because users on mobile are so lazy to learn new things, usually they rely on their past experience.)

我建议你们不要改变标签的默认外观,因为安卓设备上的用户有自己的用户体验,你会否定过去的体验,所以不要强迫他们学习新的标签体验(因为用户在移动设备上很懒惰学习新事物,通常他们依赖于他们过去的经验。)

See Pure Androidfor more.

有关更多信息,请参阅纯 Android

However if you want to go ahead, I've customized the default AndroidTabs to be look like iPhonetabs. Which is simple and features default Androidtabs' ui components (?T?a?b?H?o?s?t?, ?T?a?b?W?i?d?g?e?t?).

但是,如果您想继续,我已将默认Android选项卡自定义为看起来像iPhone选项卡。这很简单,并具有默认Android选项卡的 ui 组件 ( ?T?a?b?H?o?s?t?, ?T?a?b?W?i?d?g?e?t?)。

Download link: GitHub, Iphone-Tab-in-Android

下载链接: GitHub, Iphone-Tab-in-Android

This sample has been upgraded to use TabLayoutand ViewPager

此示例已升级为使用TabLayoutViewPager

Relavent Blog entry can be found here:

相关博客条目可以在这里找到:

iPhone like Tabs in Android.

iPhone 就像 Android 中的 Tabs。

The screenshot:

截图:

tabs at bottom screenshot

屏幕截图底部的选项卡

I have also cutomized the tabhost to look like Raised Center Tab.

我还对 tabhost 进行了裁剪,使其看起来像凸起的中心标签。

Raised Center Screenshot

凸起中心截图

to download RaiseCenterTab, please go here GitHub: RaisedCenterTab.

下载 RaiseCenterTab,请到这里GitHub: RaisedCenterTab

回答by Alex Volovoy

You'll need to build this control yourself. Few options:

您需要自己构建此控件。几个选项:

  • use RadioGroupand put custom radio buttons there and customize hell of it.

  • build this control from scratch, inherit it from one of the layouts ( Frame, Relative, Linear ) and build the behavior you need.

  • You can also take TabHost src, and use it as a base for your control

  • 使用RadioGroup并将自定义单选按钮放在那里并自定义它。

  • 从头开始构建此控件,从布局之一( Frame、Relative、Linear)继承它并构建您需要的行为。

  • 您还可以使用 TabHost src,并将其用作控件的基础

回答by Tayyab Akram

You can look at: https://github.com/mta452/iTab

你可以看看:https: //github.com/mta452/iTab

The plus point of this is that it automatically does images shaping with gradient like iOS does.

这样做的好处是它会像 iOS 一样自动进行渐变图像整形。

Screenshot:

截屏:

Screenshot of iTab

iTab 的屏幕截图

回答by Janusz

Your screenshot has the android 1.6. style. If you are using a tabhost on a newer version and simply put it on the bottom of the screen it will look very much like the iphone version.

您的屏幕截图具有 android 1.6。风格。如果您在较新版本上使用 tabhost,只需将其放在屏幕底部,它就会看起来非常像 iPhone 版本。

I wouldn't change to much at the UI of android simply give it a resemblance to the iphone look and feel(same icons) and stay with the rest in the android style. This will make the app look familiar to the users.

我不会在 android 的 UI 上做太多改变,只是让它与 iphone 的外观和感觉(相同的图标)相似,并保持 android 风格的其余部分。这将使应用程序看起来对用户来说很熟悉。

To achieve the same look for the icons just use an xml definition of you drawable with a selected and a not selected state of the button like it looks on the iphone. To set an icon use the setIndicatormethod of the tabspec.

要实现相同的图标外观,只需使用可绘制的 xml 定义,按钮的选择和未选择状态就像在 iphone 上一样。要设置图标,请使用tabspec 的 setIndicator方法。

You can somewhat style the tabhost by setting a background or a style for the tabwidget. But the actual inner part of the widget will be drawn above you style and background

您可以通过为 tabwidget 设置背景或样式来设置 tabhost 的样式。但是小部件的实际内部部分将绘制在您的样式和背景之上