Android Market-like tabbar

℡╲_俬逩灬. 提交于 2019-12-19 12:08:42

问题


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

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


回答1:


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.




回答2:


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/




回答3:


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);



回答4:


You can do this job by changing the tab.xml file. In tab.xml in linear layout, first use one child layout, which contains image and label(android market) Below this child layout, put tab host and frame layout. You can achieve this task then.



来源:https://stackoverflow.com/questions/3255698/android-market-like-tabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!