Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4613942
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:37:33+00:00 2026-05-22T01:37:33+00:00

I have a TabHost with a TabWidget. I want to customize the selected and

  • 0

I have a TabHost with a TabWidget. I want to customize the selected and unselected states for the tab. I’m not sure how to put all of these XML files together so that I can have customized tabs?

<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">
        <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="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:padding="5dp" />
            </LinearLayout>
        </TabHost>

Here is my selector xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!--  Active tab -->
    <item android:state_selected="true" android:state_focused="false"
        android:state_pressed="false" android:drawable="@drawable/tab_selected" />
    <!--  Inactive tab -->
    <item android:state_selected="false" android:state_focused="false"
        android:state_pressed="false" android:drawable="@drawable/tab_deselected" />
    <!--  Pressed tab -->
    <item android:state_pressed="true" android:drawable="@android:color/transparent" />
    <!--  Selected tab (using d-pad) -->
    <item android:state_focused="true" android:state_selected="true"
        android:state_pressed="false" android:drawable="@android:color/transparent" />
</selector>

Here is the selected state:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#97150c" android:centerColor="#7F7F7F"
        android:endColor="#b4190d" android:angle="-90" />
</shape>

Here is the unselected state:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#acacac" android:centerColor="#7F7F7F"
        android:endColor="#d7d7d7" android:angle="-90" />
</shape>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:37:33+00:00Added an answer on May 22, 2026 at 1:37 am

    The following code will do it, where tw is the TabWidget
    ‘

        for (int i = 0; i < tw.getChildCount(); i++)
        {
            View v = tw.getChildAt(i);
            v.setBackgroundDrawable(null);
            v.setOnTouchListener(new OnTouchListener()
            {
    
                @Override
                public boolean onTouch(View v, MotionEvent event)
                {
    
                    // Change the icon and background colors
                    TabWidget tw = getTabWidget();
                    for (int i = 0; i < tw.getChildCount(); i++)
                    {
                        View vv = tw.getChildAt(i);
                        vv.setBackgroundDrawable(null);
                        vv.setId(0);
                    }
    
                    NonScalingBackgroundDrawable nsbd = new NonScalingBackgroundDrawable(getApplicationContext(), v, R.drawable.nav_highlight);
    
                    v.setBackgroundDrawable(nsbd);
    
                    v.setId(1);
                    return false;
    
                }
    
            });
        }
    }
    

    ‘

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have TabHost with three tabs. One of these tabs contains ListActivity. I want
I have a TabHost, where the tab content is a ViewFlipper: <TabHost> <LinearLayout> <TabWidget
I have created a custom tab layout which look like this,I want to make
I have created a custom tabbar in my application (using TabHost and TabWidget ).
Hi i have two tabs in my tab widget,i want to apply the two
I have created an tab host..what i want to do is to change the
I have a layout with a TabHost/TabWidget like this: The blue box is a
I have 4 tabs that I load using a TabHost and TabWidget using the
I have an application with various tabs (on a tabhost). Each tab is an
I have this layout file in my android application: <?xml version=1.0 encoding=utf-8?> <TabHost xmlns:android=http://schemas.android.com/apk/res/android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.