Custom font for ActionBarSherlock tabs

actionbarsherlock, android

Solution

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);
}

Problem

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); ```

Original source

Related problems