4

I want to set the background (red image) on selected tab bar.

Initially I set like this

enter image description here

When i change in the code

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/selected_tab"
          android:state_selected="true" />

</selector>

Its look like

enter image description here

My requirement to look like below this. Please help to achieve this.

enter image description here

N Sharma
  • 33,489
  • 95
  • 256
  • 444

2 Answers2

1

you need to do like this way

For Tab background you need to create selector like this way

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- When selected, use grey -->
    <item android:drawable="@drawable/selected_tab"
          android:state_selected="true" />

    <item android:drawable="@drawable/default_tab"/>
</selector>

now you can create Button with different layout for your tab button like this way. For this requirement Button View to set your tab icon at drawable top with text.

tab_add_photo_btn.xml

<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@id/tab_search"
    android:background="@drawable/tab_selector"
    android:drawableTop="@drawable/add_photo_icon"
    android:text="ADD PHOTO"
    android:textColor="#fff"
    android:padding="10dp"/>
Pratik
  • 30,639
  • 18
  • 84
  • 159
0

I feel its nothing to do with XML coding .. just make some design trick

you need to make two different twiky images for each tab icon .

  • make Image background of tab which have little top part transparent (Not selected resource )

  • make selected image with same size with contain selected background (Selected resource )

dharmendra
  • 7,835
  • 5
  • 38
  • 71
  • 1
    But when i do this then its not cover the space. Please look second image where you find the red background color image appear small instead of many blank space there – N Sharma Jul 06 '13 at 06:34
  • You have not got my answer correctly , you dont need to make icon without black background , make icon with those black background and set it as tab background . – dharmendra Jul 06 '13 at 07:25