0

When I use views as tabSpec indicator the view is the same when a tab is selected or not.

Is there any way to use different views like when we use different drawable (selector) for the selected tab?

I already tried using the selector but it only allow to change the icon. What I want is the use a custom view and still be able to use different views for the different tab states.

Here is my code:

View profilInd = getLayoutInflater().inflate(R.layout.tabs_profil_layout, null);
Intent profilIntent = new Intent(this, MyProfilActivity.class);
tabHost.addTab(tabHost.newTabSpec("profil").setIndicator(profilInd).setContent(profilIntent));

The tabs_profil_layout layout is a simple LinearLayout with an ImageView and a TextView.

KLiFF
  • 382
  • 2
  • 18

1 Answers1

2

What you want to do is use a selector in your view/drawable which will change between the selected and not selected states.

This question covers some similar topics: Android : Customizing tabs on state : How do I make a selector a drawable

Essentially you will be making a drawable resource that looks something like this:

 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:drawable="@drawable/button_pressed" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/button_focused" /> <!-- focused -->
     <item android:drawable="@drawable/button_normal" /> <!-- default -->
 </selector>

Which you will then assign to the tab.

You can learn more about selectors and Drawable here.

Community
  • 1
  • 1
mtmurdock
  • 12,756
  • 21
  • 65
  • 108
  • Hi, thinks for your answer. what I finally did is this: - I created a selctor with two background png files. - I created a view that I used as a tab indicator (the java code above didn't change). Within this view I have a LinearLayout that uses the selector as a background. – KLiFF May 18 '12 at 08:47