0

我正在尝试创建不填满整个宽度的选项卡。

我目前正在使用 ActionBar 选项卡,并且也将其设为蓝色 + 选项卡,但不幸的是它会将其拉伸以使其宽度相等。

有什么方法可以使用操作栏选项卡来做到这一点?如果没有,我可以使用 TabHost/TabWidget 吗?我希望页面的内容是一个控制实际页面内容的 ViewPager。

我当前的 XML 文件看起来很简单:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

当我试用 TabHost 时,我尝试了这个:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:id="@android:id/tabhost">

    <LinearLayout 
            android:id="@+id/LinearLayout01"
            android:orientation="vertical" 
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >

          <TabWidget 
                android:id="@android:id/tabs"
                android:layout_height="wrap_content" 
                android:layout_width="0dp"
                android:layout_weight="1"
                >

            </TabWidget>
            <Button
                android:layout_height="wrap_content"
                android:layout_width="46dp"
                android:background="#00F"
                android:text="+"
                >
            </Button>

        </LinearLayout>
        <FrameLayout 
            android:id="@android:id/tabcontent"
            android:layout_height="fill_parent"
             android:layout_width="fill_parent">
        </FrameLayout>

    </LinearLayout>

这给了我类似的东西:

但我不知道我的 ViewPager 适合它。

我也无法弄清楚如何对操作栏选项卡进行以下自定义:

  1. 小写而不是全部大写
  2. 标签高度
  3. 选定的条形颜色
  4. 所选字体
  5. 选中/未选中的文本颜色
  6. 字体大小

任何想法,将不胜感激。谢谢!

4

1 回答 1

0

将“TabWidget”添加到“LinearLayout”或任何布局,并在需要时添加。

例如让选项卡仅填充屏幕宽度的 0.65

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dip"
            android:layout_marginBottom="6dip"
            android:baselineAligned="false"
            android:orientation="horizontal" >

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.65"
                android:orientation="horizontal" />

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_gravity="right"
                android:layout_weight="0.35"
                android:background="@color/transparent" />
        </LinearLayout>
于 2013-10-22T01:43:19.923 回答