android 在底部 tabHost 顶部获取标签条

发布于 2025-01-08 14:05:58 字数 1683 浏览 3 评论 0原文

我有一个底部选项卡的布局。但是,我无法在 tabHost 之上设置条带。怎么做呢?谢谢。

这是我的主要布局:

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

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"                    
            android:layout_height="wrap_content"
            android:layout_weight="0"

     />
    </LinearLayout>

</TabHost>

也是选项卡样式的选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

 <item android:state_pressed="true" >
    <shape>
        <gradient
            android:startColor="#aa3434"
            android:endColor="#432233"
            android:angle="270"
             />
    </shape>
</item>

 <item android:state_selected="true" >
    <shape>
        <gradient
            android:startColor="#aa3434"
            android:endColor="#432233"
            android:angle="270" />
    </shape>
</item>

在此处输入图像描述

I have a layout for bottom tabs. However, I am not able to set the strip on top of tabHost. How to do it? Thank you.

here my main layout:

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

     <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"                    
            android:layout_height="wrap_content"
            android:layout_weight="0"

     />
    </LinearLayout>

</TabHost>

and also a selector for tab style:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

 <item android:state_pressed="true" >
    <shape>
        <gradient
            android:startColor="#aa3434"
            android:endColor="#432233"
            android:angle="270"
             />
    </shape>
</item>

 <item android:state_selected="true" >
    <shape>
        <gradient
            android:startColor="#aa3434"
            android:endColor="#432233"
            android:angle="270" />
    </shape>
</item>

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平安喜乐 2025-01-15 14:05:58

试试这个代码

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />
    </LinearLayout>

</TabHost>

Try this code

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />
    </LinearLayout>

</TabHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文