简体   繁体   中英

Tab Selection Indicator

In my app i am using Tabs, by default it looks like this:

在此处输入图片说明

and now, i want to show different color [like:dark blue] for selected tab in rounded corner shape

I am using below XMLs to create above Tabs

using this to create rounded shape tabs, with white corner, mytab_custom.xml:-

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#44b8ec"/>    

    <stroke android:width="1dp"
            android:color="#ffffff" />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp" /> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
             android:topLeftRadius="7dp" android:topRightRadius="7dp" />

</shape>

and using this, to show Image in Tabs, tab_contact.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/birthday_text"
        android:state_selected="true" />
    <item android:drawable="@drawable/birthday_text" />
</selector> 

tab_indicator.xml:-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="0dip"
    android:layout_height="40dip"    
    android:layout_weight="1"
    android:orientation="vertical"
    android:padding="5dp">

    <ImageView 
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/icon"
    /> 

</RelativeLayout>

main.xml:-

<?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"
    android:background="@drawable/btn_background"
  >

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/check"
       />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:padding="5dp" />

    </LinearLayout>

</TabHost>

The problem might lie here:-

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/birthday_text"
        android:state_selected="true" />
    <item android:drawable="@drawable/birthday_text" />
</selector> 

try using a different image here:-

<item android:drawable="@drawable/birthday_text"
            android:state_selected="true" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM