How to resize actionbar tabs

2019-09-19 01:49发布

问题:

I looked all stackoverflow's topics about it, and none of these solutions - like this one:

<style name="Widget.Holo.Tab" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
    <item name="android:height">#dp</item>
</style>

<style name="Your.Theme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarTabStyle">@style/Widget.Holo.Tab</item>
</style>

http://stackoverflow.com/questions/9286638/actionbar-tabs-height

that changed nothing - (none of these) helped me.

I have 5 tabs, without title, just icon, but I need it to be all visible at the same time, so it have to be small to fit all. How can I make the tab has that size?

回答1:

Change the height of your ActionBar to change your tabs size:

<item name="android:actionBarSize">#dp</item>

Hope this helps.


EDIT:

Maybe you can customize a TabBar yourself with ImageViews, see below:

<!-- Tab Nav -->

<TableLayout
    android:id="@+id/TabNavMain"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="0dip"
    android:stretchColumns="5" >

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|center_horizontal"
        android:weightSum="5">

        <ImageView
            android:id="@+id/TabNav1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="onNavSelected"
            android:clickable="true" />

        <ImageView
            android:id="@+id/TabNav2"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="onNavSelected"
            android:clickable="true" />

        <ImageView
            android:id="@+id/TabNav3"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="onNavSelected"
            android:clickable="true" />

        <ImageView
            android:id="@+id/TabNav4"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="onNavSelected"
            android:clickable="true" />

        <ImageView
            android:id="@+id/TabNav5"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="onNavSelected"
            android:clickable="true" />

    </TableRow>

</TableLayout>

<!-- End Tab Nav -->  

And in your Activity, you can make a NavListener:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...  
    NavListener navListener = new NavListener();  
}  

private class NavListener implements View.OnClickListener {
    @Override
    public void onNavSelected(View v) {
         switch (v.getId()) {
            case R.id.TabNav1:
                // do something...
            break;
            case R.id.TabNav2:
                // do something else...
            break;
            case R.id.TabNav3:
                // do something...
            break;
            // ...
         }
    }
};  

Hope this helpful.