如何在TabWidget中创建自定义字体样式?

时间:2012-09-25 15:25:59

标签: android eclipse tabwidget

enter image description here

我想更改我在Android应用中创建的标签中的字体。

这是我的xml文件:

  

<com.markupartist.android.widget.ActionBar
    android:id="@+id/actionbar"
    style="@style/ActionBar" />

<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="fill_vertical"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/darker_gray"
            android:orientation="horizontal"
            android:paddingTop="0dp"
            android:tabStripEnabled="true" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost> 

这是我的活动:

  

public class Home_Activity扩展了TabActivity {

private static final int DIALOG_REALLY_EXIT_ID = 0;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
    actionBar.setTitle(getString(R.string.app_name));

    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, "I've Been Using");
    intent.putExtra(Intent.EXTRA_TEXT, "BikeDSS Application by: Chocholuis");

    final Action shareAction = new IntentAction(this, Intent.createChooser(
            intent, "Share BikeDSS"), R.drawable.icon_share);
    actionBar.addAction(shareAction);

    Action searchAction = new IntentAction(this, new Intent(this,
            search_activity.class), R.drawable.icon_search);
    actionBar.addAction(searchAction);

    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost(); // The activity TabHost
    TabHost.TabSpec spec; // Reusable TabSpec for each tab
    // Intent intent; // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, Tab_Bike_Activity.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("bike")
            .setIndicator("Bike", res.getDrawable(R.drawable.sepeda))
            .setContent(intent);
    tabHost.addTab(spec);

    // Do the same for the other tabs
    intent = new Intent().setClass(this, Tab_Brand_ListView_Activity.class);
    spec = tabHost.newTabSpec("information")
            .setIndicator("Information", res.getDrawable(R.drawable.info))
            .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this,
            Tab_Shop_Repair_ListView_Activity.class);
    spec = tabHost
            .newTabSpec("repair")
            .setIndicator("Shop and Bicycle Repair",
                    res.getDrawable(R.drawable.bengkel)).setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);

} 

是否可以更改字体?我真的需要帮助。 感谢

1 个答案:

答案 0 :(得分:0)

您必须创建自己的tablayout。有关tabhost自定义的教程,请参阅此链接:http://ondrejcermak.info/en/programovani/custom-tabs-in-android-tutorial/