Make your tab drawable a selector drawable that picks other drawables based
on its state, like the standard tab drawable:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false" android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/tab_unselected" />
<item android:state_focused="false" android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/tab_selected" />
<!-- Focused states -->
<item android:state_focused="true" android:state_selected="false"
android:state_pressed="false" android:drawable="@drawable/tab_focus"
/>
<item android:state_focused="true" android:state_selected="true"
android:state_pressed="false" android:drawable="@drawable/tab_focus"
/>
<!-- Pressed -->
<item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>
On Thu, Dec 4, 2008 at 2:45 PM, mscwd01 <[EMAIL PROTECTED]> wrote:
>
> Anyone? I've spent most of today on this problem and its starting to
> get old ;)
>
> On Dec 4, 6:43 pm, mscwd01 <[EMAIL PROTECTED]> wrote:
> > This is not so much a problem, more a question about how to achieve
> > something...
> >
> > I have a tabhost with three tabs. I have 6 icons, 3 in colour and 3 an
> > exact copy but in grayscale.
> >
> > What I want to do is have the coloured version of the icon displayed
> > when the tab is active i.e. being viewed. Otherwise I want the other
> > inactive tabs to show the grayscale version of their icon - and change
> > to the coloured version if they are clicked.
> >
> > So I want a tab to show a coloured icon if active and a grayscale icon
> > if inactive...
> >
> > Any ideas how to achieve this anyone?
> >
> > I have played around with the TabHost onTabChangeListener but havent
> > been able to find a solution.
> >
> > Ideally I need something like:
> >
> > tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
> >
> > public void onTabChanged(String arg0) {
> > int selectedTab = tabs.getCurrentTab();
> >
> > // Update newly selected tab to display
> > colorful icon
> > // Update previously selected tab to
> > display greyscale icon
> > }
> > });
> >
> > Thanks
> >
>
--
Dianne Hackborn
Android framework engineer
[EMAIL PROTECTED]
Note: please don't send private questions to me, as I don't have time to
provide private support. All such questions should be posted on public
forums, where I and others can see and answer them.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---