簡體   English   中英

如何調整動作欄標簽

[英]How to resize actionbar tabs

我查看了所有關於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個標簽,沒有標題,只有圖標,但是我需要同時顯示所有標簽,因此它必須很小以適合所有人。 如何使標簽具有該大小?

更改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;
            // ...
         }
    }
};  

希望對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM