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 7758129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:16:36+00:00 2026-06-01T13:16:36+00:00

I am using a TabHost which has 3 tabs. Each tab has a image

  • 0

I am using a TabHost which has 3 tabs. Each tab has a image + text.

spec = tabHost.newTabSpec("MyTasks")
           .setIndicator(Html.fromHtml("<b><H2>My Tasks</H2></b>"),  getResources().getDrawable(R.drawable.task ))
               .setContent(intent);    
   tabHost.addTab(spec); 

I want to change image when I select a tab. I used following code to change it …

 TabWidget tw = getTabWidget(); 
   View leftTabView = tw.getChildAt(0); 
   leftTabView.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab1_drawable)); 

tab1_drawable is a xml (selector and items for each state). THIS IS SETTING AND CHANGING BACKGROUND NOT THE IMAGE I SET. How can I change it?

  • 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-06-01T13:16:38+00:00Added an answer on June 1, 2026 at 1:16 pm

    Instead of changing the drawable through code, why not use a state-list drawable? Then you’d just specify a different drawable for the tab when it is selected.

    Example, ic_tab_tasks.xml:

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

    Then, when you’re setting the tab indicator’s drawable initially, just use the state-list drawable.

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

Sidebar

Related Questions

I have an application with various tabs (on a tabhost), each tab is an
I am using tabs in my application . Each tab is pointing to 3
I have created four tabs using tabhost, and placed four listviews in each like
I have an android activity in which I'm using tabs. public class UnitActivity extends
I have worked in tab bar, using TabHost to develop the tab1, tab2 and
Possible Duplicate: Separate Back Stack for each tab in Android using Fragments I've recently
I am using a tab ,In which tab buttons add melodramatically,My requirement is to
I've created a TabHost example with 1 tab which is running fine. I'm adding
I am using the TabHost in my application, I am using four Tabs in
I have 4 tabs that I load using a TabHost and TabWidget using the

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.