自定义字体ActionBarSherlock标签 [英] Custom font for ActionBarSherlock tabs

查看:147
本文介绍了自定义字体ActionBarSherlock标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置字体为视频,并在 ActionBarSherlock 图片选项卡。我使用了下列code这样做。它显示出准确的ICS,但不是在低版本的设备,但我已经表明在此应用程序的其它部分精确的输出设置类型的脸像...

  a.settypeface(ab.tttf);
a.settext(VIDEO);
 

但怎么做我在这个code设置在动作条 A 字体

  mTab​​sAdapter.addTab(bar.newTab()的setText(图像),AFragment.class,NULL);
mTabsAdapter.addTab(bar.newTab()的setText(VIDEO),BFragment.class,空);
 

解决方案

好。我发现自己一些地方对左右。

首先要在用这样的一个XML文件:tab_title.xml

 <的TextView
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:ID =@ + ID / action_custom_title
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=我的自定义标题
机器人:文字颜色=#FFF
机器人:TEXTSIZE =18sp
机器人:paddingTop =5DP/>
 

然后在类,你在实例化你的动作条使用该code设置在每个标签的文本。 (这个例子是使用ActionBarSherlock。)

 动作条酒吧= getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

的String [] tabNames = {选项卡1,标签2,标签3};

的for(int i = 0; I< bar.getTabCount();我++){
    LayoutInflater充气= LayoutInflater.from(本);
    查看customView = inflater.inflate(R.layout.tab_title,NULL);

    TextView的titleTV =(TextView中)customView.findViewById(R.id.action_custom_title);
    titleTV.setText(tabNames [I]);
    //在这里你还可以添加你想要的任何其他样式。

    bar.getTabAt(ⅰ).setCustomView(customView);
}
 

I want to set font for the "Video" and "Image" tabs in ActionBarSherlock. I have used the following code to do so. Its showing accurately in ICS but not in the lower version device but I have shown accurate output in the other part of this application by setting TYPE FACE like ...

a.settypeface("ab.tttf");
a.settext("VIDEO");

But how to do I set a TypeFace in the ActionBar in this code:

mTabsAdapter.addTab(bar.newTab().setText("IMAGE"), AFragment.class, null);
mTabsAdapter.addTab(bar.newTab().setText("VIDEO"), BFragment.class, null);

解决方案

Okay . I found it myself some where on SO.

First make an xml file with this in it: tab_title.xml

<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/action_custom_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Custom title"
android:textColor="#fff"
android:textSize="18sp"
android:paddingTop="5dp" />

Then in the class where you in instantiate your ActionBar use this code to set the text on each of the tabs. (This example is using ActionBarSherlock.)

ActionBar bar = getSupportActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

String[] tabNames = {"Tab 1","Tab 2","Tab 3"};

for(int i = 0; i<bar.getTabCount(); i++){
    LayoutInflater inflater = LayoutInflater.from(this);
    View customView = inflater.inflate(R.layout.tab_title, null);

    TextView titleTV = (TextView) customView.findViewById(R.id.action_custom_title);
    titleTV.setText(tabNames[i]);
    //Here you can also add any other styling you want.

    bar.getTabAt(i).setCustomView(customView);
}

这篇关于自定义字体ActionBarSherlock标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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