Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中实现像Iphone这样的Tab主机?_Android_Android Layout_Styles_Android Tabhost_Android Style Tabhost - Fatal编程技术网

如何在android中实现像Iphone这样的Tab主机?

如何在android中实现像Iphone这样的Tab主机?,android,android-layout,styles,android-tabhost,android-style-tabhost,Android,Android Layout,Styles,Android Tabhost,Android Style Tabhost,我是安卓的新手。我正在做android应用程序。我必须在android上做TabHost看起来像iPhone,我在分享图像。请帮我布置一下 我尝试了这么多,但没有得到确切的解决方案 您可以为选项卡应用自定义形状和选择器 shape\u tab\u selected.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"

我是安卓的新手。我正在做android应用程序。我必须在android上做TabHost看起来像iPhone,我在分享图像。请帮我布置一下

我尝试了这么多,但没有得到确切的解决方案


您可以为选项卡应用自定义形状和选择器

shape\u tab\u selected.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- radius should be half of the desired TabLayout height -->
    <corners android:radius="15dp" />
    <solid android:color="@color/colorWhite"/>

</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- color of the selected tab -->
    <solid android:color="@android:color/transparent" />


</shape>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- drawable for selected tab -->
    <item
        android:drawable="@drawable/shape_tab_selected"
        android:state_selected="true"/>

    <!-- drawable for unselected tab -->
    <item
        android:drawable="@drawable/shape_tab_unselected"
        android:state_selected="false"/>

</selector>

形状选项卡未选中。xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- radius should be half of the desired TabLayout height -->
    <corners android:radius="15dp" />
    <solid android:color="@color/colorWhite"/>

</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- color of the selected tab -->
    <solid android:color="@android:color/transparent" />


</shape>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- drawable for selected tab -->
    <item
        android:drawable="@drawable/shape_tab_selected"
        android:state_selected="true"/>

    <!-- drawable for unselected tab -->
    <item
        android:drawable="@drawable/shape_tab_unselected"
        android:state_selected="false"/>

</selector>

选择器_tab.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- radius should be half of the desired TabLayout height -->
    <corners android:radius="15dp" />
    <solid android:color="@color/colorWhite"/>

</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- color of the selected tab -->
    <solid android:color="@android:color/transparent" />


</shape>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- drawable for selected tab -->
    <item
        android:drawable="@drawable/shape_tab_selected"
        android:state_selected="true"/>

    <!-- drawable for unselected tab -->
    <item
        android:drawable="@drawable/shape_tab_unselected"
        android:state_selected="false"/>

</selector>

在活动布局中添加选项卡布局并将选择器选项卡设置为选项卡背景

<com.google.android.material.tabs.TabLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorGray"
app:tabGravity="fill"
app:tabBackground="@drawable/selector_tab"
app:tabIndicatorColor="@android:color/transparent"
app:tabIndicatorHeight="0dp"
app:tabMode="fixed"
app:tabRippleColor="@null"
app:tabSelectedTextColor="@color/colorBlack"
app:tabTextColor="@color/colorBlack"  />

根据需要自定义其他属性。你可以找到更多关于TabLayout的信息

就这些


快乐编码!:)

谢谢你的回答。我正在寻找TabHost,您也可以使用tab布局。如果您要求某人为您编写整个TabHost端口,这对于堆栈溢出问题来说太宽泛了。否则,不清楚现有解决方案存在哪些问题。