如何在 Android 中更改标签样式? [英] How to change tab style in Android?
本文介绍了如何在 Android 中更改标签样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的 Android 标签看起来像官方 TWitter 应用中的一样扁平和简单.如何使用样式/主题定义覆盖默认(浅色)主题并更改选项卡的背景图像?
I'd like to my Android tabs to look flat and simple like the ones in the official TWitter app. How can I override the default (light) theme and change the background images for the tabs using style/theme definitions?
推荐答案
您可以通过代码调整选项卡 - 这是我的应用程序的摘录,但您也可以直接分配主题而不是背景图像.(我还没有使用通过xml属性的方法,不确定是否也可以使用).
You could adjust the tabs via code - here's an excerpt from my application, but you could also assign themes instead of the background image directly. (I haven't used a way via xml attributes yet, not sure if that's available as well somehow).
private void initTabs() {
tabs = (TabHost) findViewById(R.id.tabhost);
tabs.setup();
tabs.setBackgroundResource(R.drawable.bg_midgray);
TabHost.TabSpec spec;
// Location info
txtTabInfo = new TextView(this);
txtTabInfo.setText("INFO");
txtTabInfo.setPadding(0, 5, 0, 0);
txtTabInfo.setTextSize(11);
txtTabInfo.setBackgroundResource(R.drawable.bg_tab_left_active_right_inactive);
txtTabInfo.setTextColor(Color.DKGRAY);
txtTabInfo.setGravity(Gravity.CENTER_HORIZONTAL);
txtTabInfo.setHeight(39);
spec = tabs.newTabSpec("tabInfo");
spec.setContent(R.id.tabInfo);
spec.setIndicator(txtTabInfo);
tabs.addTab(spec);
...
}
这篇关于如何在 Android 中更改标签样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文