新手上路:如何更改标签的字体大小? [英] Newbie: How to change tab font size?

查看:197
本文介绍了新手上路:如何更改标签的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了Android开发的标签布局教程以实现一个简单的标签布局。

I follow the android develops tutorial of tab layout to implement a simple tab layout.

根据该教程,我得到了我的脑海里的问题,那就是如何更改标签字体大小??

Based on that tutorial, I got an question in my mind, that's how to change the tab font size??

我试图通过添加属性安卓更改标签字体大小:TEXTSIZE =8DIP< TabWidget ...> 布局 XML 文件:

I tried to change the tab font size by adding the attribute android:textSize="8dip" in <TabWidget ...> of the layout xml file :

<TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

    android:textSize="8dip" 
/>

,但它并不需要任何效果。

but it does not take any effect.

任何人都可以提供合适的方法来改变标签上的字体大小?

Anyone can provide the right way to change the font size on the tab?

推荐答案

在这里,你走你的tabactivity使用

Here you go in your tabactivity use

Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = (TabHost) getTabHost(); // The activity TabHost

TabHost.TabSpec spec; // Resusable TabSpec for each tab
Typeface localTypeface1 = Typeface.createFromAsset(getAssets(),
        "fonts/arial.ttf");

修改启动

tabHost.getTabWidget().setBackgroundDrawable( getResources().getDrawable(R.drawable.bluenavbar));

修改完

TextView txtTab = new TextView(this);
txtTab.setText(getString(R.string.top_news));
txtTab.setPadding(8, 9, 8, 9);
txtTab.setTextColor(Color.WHITE);
txtTab.setTextSize(14);
txtTab.setTypeface(localTypeface1);
txtTab.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
txtTab.setBackgroundResource(R.drawable.tab_news);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("topNews").setIndicator(txtTab).setContent(new Intent(this, TopNewsGroup.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
tabHost.addTab(spec);

现在你就可以改变的颜色 尺寸字体的文字

Now you'll be able to change the color, size and typeface of the text

这篇关于新手上路:如何更改标签的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆