【问题标题】:How to resize actionbar tabs如何调整操作栏选项卡的大小
【发布时间】:2013-11-20 13:22:29
【问题描述】:

我查看了有关它的所有 stackoverflow 主题,但没有一个解决方案 - 像这个:

<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

没有任何改变——(这些都没有)帮助我。

我有 5 个标签,没有标题,只有图标,但我需要它们同时可见,所以它必须很小才能适合所有人。我怎样才能让标签有这样的大小?

【问题讨论】:

    标签: java android tabs android-actionbar android-styles


    【解决方案1】:

    更改ActionBar 的高度以更改标签大小:

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

    希望这会有所帮助。


    编辑:

    也许你可以用ImageViews自己定制一个TabBar,见下文:

    <!-- 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 -->  
    

    并且在您的Activity 中,您可以创建一个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;
                // ...
             }
        }
    };  
    

    希望这有帮助。

    【讨论】:

    • 这只是按下标签,我想要的是缩短它们,减少它的宽度。 =/
    • 一次容纳5个标签,每个标签只显示一个图标,没有标题。
    • 我认为解决您问题的最佳方法是使用五个ImageViews 自己自定义一个Tabbar
    • 我觉得这对我来说太高级了。 ^^'我不明白如何使这项工作。但我使用 TabHost 解决了这个问题。也许这会帮助别人。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多