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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:14:38+00:00 2026-06-07T18:14:38+00:00

I have the following activity code for a tabbed application. public class TabbedActivity extends

  • 0

I have the following activity code for a tabbed application.

public class TabbedActivity extends TabActivity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabbedactivity);        

        TabHost tabHost = getTabHost();         

        TabSpec photospec = tabHost.newTabSpec("RP");
        // setting Title and Icon for the Tab
        photospec.setIndicator("RP", getResources().getDrawable(R.drawable.tabrp));
        Intent photosIntent = new Intent(this, RP.class);
        photospec.setContent(photosIntent);

        // Tab for Songs
        TabSpec songspec = tabHost.newTabSpec("MP");
        songspec.setIndicator("MP", getResources().getDrawable(R.drawable.tabmp));
        Intent songsIntent = new Intent(this, MP.class);
        songspec.setContent(songsIntent);

        tabHost.addTab(photospec);
        tabHost.addTab(songspec);           
    }       
}

The tabbedactivity.xml is defined as below:

<?xml version="1.0" encoding="utf-8"?>
<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">
        <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"/>
    </LinearLayout>
</TabHost>

I have added tabmp.xml and tabrp.xml as follows:

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

The colors are defined in color.xml. The application runs, but the color on the tabs is still the default black when active, gray when not active and blue when pressed, which are the default android colors for tabs. The tabmp.xml and tabrp.xml does not seen to work. Am I doing something wrong here?

  • 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-07T18:14:40+00:00Added an answer on June 7, 2026 at 6:14 pm

    The drawing resource needs to be set as the background of the tab view. You can do one of two things:

    1. Once you’ve created the tab:

       tabHost.getTabWidget().getChildAt(THE_CHILDS_POSITION_IN_THE_HOST).setBackgroundResource(R.drawable.tabmp.xml);
      
    2. Or create a custom layout for your tab

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/tabsLayout" android:layout_width="fill_parent"
      android:layout_height="fill_parent" android:background="@drawable/tab_bg_selector"
      android:padding="10dp" android:gravity="center" android:orientation="vertical">
      
          <TextView android:id="@+id/tabsText" android:layout_width="wrap_content"
              android:layout_height="wrap_content" android:text="Title"
              android:textSize="15dp" android:textColor="@drawable/tab_text_selector"
              android:textStyle="bold" />
      </LinearLayout>
      

      and then when creating your tab:

      View tabview = LayoutInflator.from(context).inflate(R.layout.tabs_bg, null);
      TextView tv = (TextView)view.findViewById(R.id.tabsText);
      tv.setText(TEXT);
      TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(i);
      tabHost.addTab(setContent);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
I have the following code in Main.java : public class Main extends Activity implements
I have the following code: public class TestSynch extends Activity { public static ArrayList<HashMap<String,String>>
I have the following Java code: public class FirstActivity extends Activity implements OnClickListener {
I have following code: public class reader extends Activity { WebView mWebView; String mFilename;
I have following code: public class ShowActivity extends ListActivity implements OnItemClickListener { /** Called
I have following code that displays an Image with letters, public class MainActivity extends
Hi All I have the following code: enter code here public class XMPPClient extends
I have an activity with following code. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
I have the following Activity: public class StartActivity extends Activity { String str =

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.