类似安卓市场的标签栏[英] Android Market-like tabbar

本文是小编为大家收集整理的关于类似安卓市场的标签栏的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

实现Android市场的最佳方法 - 类似Android市场的标签栏(应用/游戏/下载)?

alt text

如果我可以使用tabhost会很棒,但我相信它不允许这种自定义级别.

推荐答案

作为cristian表示,它绝对可以使用TabHost,甚至不需要使用他链接的androidtabs代码.如SDK级别4(即Android 1.6)您可以将View传递给 TabHost.TabSpec.setIndicator() ,这将允许您完全控制选项卡的外观.

但是,点击市场中的任何按钮都会打开新的活动,因此,使用简单的Button S可能会更紧密地反映出比Tabhost的行为.

在您也需要支持1.5的情况下,您也可以从这篇文章.它包含来自Android 1.6的TabHost等.将其复制到您的项目中应该工作,即使是Android 1.5.然后,您将使用您提供的setIndicator(View V).

其他推荐答案

可以使用TabHost.甚至更好,您可以找到如何在此处执行的功能齐全的示例: http://代码. google.com/p/androidtabs/

其他推荐答案

让您尝试以下代码:

TabHost.TabSpec spec;  // Reusable TabSpec for each tab
TextView txtTabInfo; // Reusable tab indicator

// Create our tab indicator
txtTabInfo = new TextView(this);
txtTabInfo.setText("videos");
txtTabInfo.setTextSize(16);
txtTabInfo.setTypeface(Typeface.DEFAULT_BOLD);
txtTabInfo.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
txtTabInfo.setBackgroundResource(R.drawable.minitab);
txtTabInfo.setMinHeight(55);

spec = tabHostMM.newTabSpec("video");
spec.setContent(R.id.mm_video);
spec.setIndicator(txtTabInfo);
tabHostMM.addTab(spec);

本文地址:https://www.itbaoku.cn/post/102744.html

问题描述

What's the best way to implement an Android Market-like tabbar (Apps/Games/Downloads)?

alt text

It would be great if I could use TabHost, but I believe it doesn't allow this level of customization.

推荐答案

As Cristian said, it's definitely possible using a TabHost, and you don't even need to use the androidtabs code that he links to. As of SDK level 4 (i.e. Android 1.6) you can pass a View to TabHost.TabSpec.setIndicator(), which will allow you to completely control the look of the tabs.

However, tapping either of those buttons in the Market opens up a new Activity, and as such, using simple Buttons might more closely reflect that behaviour than a TabHost would.

In the event that you need to support 1.5 as well, you could check out the zip archive from this post. It contains TabHost etc. from Android 1.6. Copying this into your project should work, even on Android 1.5. You'll then have setIndicator(View v) available to you.

其他推荐答案

It's possible to do using TabHost. Even better, you can find a fully functional example of how to do it here: http://code.google.com/p/androidtabs/

其他推荐答案

Let try this code:

TabHost.TabSpec spec;  // Reusable TabSpec for each tab
TextView txtTabInfo; // Reusable tab indicator

// Create our tab indicator
txtTabInfo = new TextView(this);
txtTabInfo.setText("videos");
txtTabInfo.setTextSize(16);
txtTabInfo.setTypeface(Typeface.DEFAULT_BOLD);
txtTabInfo.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
txtTabInfo.setBackgroundResource(R.drawable.minitab);
txtTabInfo.setMinHeight(55);

spec = tabHostMM.newTabSpec("video");
spec.setContent(R.id.mm_video);
spec.setIndicator(txtTabInfo);
tabHostMM.addTab(spec);