安卓:文本和彩色标签上,标签布局 [英] Android: text and color on tabs , Tab Layout
问题描述
我使用Tab键的布局和我想要做的两件事情:
I'm using Tab Layout and I want to do two things:
- 设置的颜色,所以它不会是灰色
- 缩小文本大小,文本不适合。
此外,该文本是大部分的图标,而不是它下面的(我能做些什么呢?)。
also, the text is in most part on the icon instead of below it (can I do something about it ?).
我如何能做到这一点任何想法?
Any ideas on how can I do this ?
编辑:我以这种方式创建一个新的标签:
edit: I'm creating a new tab in this manner:
spec = tabHost.newTabSpec("artists").setIndicator(
"Artists",
res.getDrawable(R.drawable.ic_tab_artists)
).setContent(intent);
tabHost.addTab(spec);
我要改变这个词的艺术家的大小。
I want to change the size of the word "artists".
推荐答案
您应该定义自己的看法。
You should define your own view.
tabHost.newTabSpec("tab1")
.setIndicator(prepareTabView(this, "title"))
.setContent(intent);
和您可以在这里改变文字大小的 tv.setTextSize(20)
and you can change the text size here tv.setTextSize(20)"
public static View prepareTabView(Context context, String text) {
View view = LayoutInflater.from(context).inflate(
R.layout.tab_indicator, null);
TextView tv = (TextView) view.findViewById(R.id.tabIndicatorTextView);
tv.setText(text);
return view;
}
tab_indicator.xml。你可以在这里改变文字大小也是的android:TEXTSIZE =20dip。有可能在这里设置的背景颜色。 的android:背景=@色/ back_color_selector_tab
tab_indicator.xml. you can change the text size here also android:textSize="20dip". it is possible to set the background color here. android:background="@color/back_color_selector_tab"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fakeNativeTabLayout" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center"
android:orientation="vertical" android:background="@color/back_color_selector_tab">
<!-- You can even define an Icon here (dont forget to set a custom icon
in your code for each Tab): <ImageView android:id="@+id/fakeNativeTabImageView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/icon" /> -->
<TextView android:id="@+id/tabIndicatorTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Tab" android:ellipsize="marquee" />
</LinearLayout>
back_color_selector_tab.xml是在不同状态的背景色自动变化的XML。
back_color_selector_tab.xml is an xml for automatic changes in background color in different states.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/state_orange" />
<item android:state_selected="true" android:drawable="@drawable/background05" /> <!-- focused -->
<item android:drawable="@drawable/background04" /> <!-- default -->
</selector>
state_orange.xml的样品
a sample of state_orange.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/orange" />
</shape>
这篇关于安卓:文本和彩色标签上,标签布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!