安卓操作栏如何填充选项卡宽度

3
我在我的操作栏选项卡中使用了自定义视图来显示进度条。我希望进度条的宽度与标签指示器的宽度相匹配。然而,自定义视图所覆盖的区域在选项卡内设置了边距,因此我无法将进度条扩展到整个选项卡的宽度。有什么好的方法吗?
以下是当前进度条的样子... progress bar in tab 进度条的宽度已设置为匹配父级宽度。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_margin="0dp"
>
        <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tab_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text = "Day 1"
        android:textAllCaps="true"
        android:textStyle="bold"
        android:textSize="13dp"
        android:layout_gravity="center"
        android:gravity="center"
        android:paddingTop="18dp"
        />

        <ProgressBar 
            style="@android:style/Widget.Holo.ProgressBar.Horizontal"
            android:id="@+id/tab_progress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="1dp"
            />

</RelativeLayout>
1个回答

1
解决方案是为androidActionBarTabStyle实现一个自定义主题。这是在使用setCustomView时定义视图的容器。我遇到的一个问题是,当将样式创建为主题时,必须以Theme为前缀,例如:Theme.MyTheme
如果不包括Theme.前缀,您的主题将不会被应用。
在样式文件中,我定义了这个样式:
<style name="withProgress" parent="@android:style/Widget.Holo.Light.ActionBar.TabView.Inverse">
    <item name="android:padding">0dp</item>
</style>

然后在主题中。

<item name="android:actionBarTabStyle">@style/withProgress</item>

事实证明,它看起来相当糟糕,但如果有人正在寻找类似的东西,那就是这样做的方法。


如果我将选项卡设置为CustomView(..),那么视图是否能够使用此主题填充选项卡?我正在使用Sherlock ActionBar,但它没有起作用。 - Ben Sewards

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接