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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:16:40+00:00 2026-05-26T06:16:40+00:00

I opend a post about this before but I feel that I can now

  • 0

I opend a post about this before but I feel that I can now (after reading some other posts) better explain what I want and rephrase it so it will be better understand.

I followed the tutorial about Tab Layout on the dev guide and I managed to create tabs with it, but I want to do some customization to it (and I did look on other posts, but either the code had many mistakes to it or it didn’t answer what I’m looking for).

  1. The first problem I have is that the test is in most part over the icon instead of below it (I used an icon with dimensions 48×48 as recommended on the dev guide). I want the tab with to act like wrap_content does.
    I also want to change the text size (I think it’s called the label).

  2. I want to use hex triplets to change the background color of the tabs, to change it between to situations : when this tab is the one selected and when it’s not.

  3. I want to be able to change the color of the line that is below the tabs, I could not find any information on how to do this.

The code I’m currently using to create a new tab is (from the dev guide):

    intent = new Intent().setClass(this, GroupsActivity.class);
    spec = tabHost.newTabSpec("groups").setIndicator("groups",
                      res.getDrawable(R.drawable.ic_tab_groups))
                  .setContent(intent);
    tabHost.addTab(spec);

(groups is the tab name).

Help is very much appreciated!

  • 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-26T06:16:41+00:00Added an answer on May 26, 2026 at 6:16 am

    Rather than trying to customize the widget tabs themselves, here is an alternate approach that I’ve used successfully on a project that may save you some headaches:

    The idea is to use a hidden TabWidget in your layout and control it with a customized LinearLayout containing Buttons. This way, you can more easily customize the buttons to look however you’d like. You’ll control the actual TabWidget in your Activity within each button’s OnClick.

    1. Create your layout with both the TabWidget and the Buttons:

          <?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">
      
          <RelativeLayout android:orientation="vertical"
              android:layout_width="fill_parent" android:layout_height="fill_parent"
              android:gravity="bottom">
              <TabWidget android:id="@android:id/tabs"
                  android:layout_width="fill_parent" android:layout_height="wrap_content"
                  android:visibility="gone" />
      
              <LinearLayout android:id="@+id/tabbar"
                  android:orientation="horizontal" android:layout_width="fill_parent"
                  android:layout_height="wrap_content">
                  <Button android:id="@+id/firstButton"
                      android:layout_alignParentTop="true" android:background="@drawable/btn_first_on"
                      android:layout_width="100dp" android:layout_height="43dp"
                      android:clickable="true"></Button>
                  <Button android:id="@+id/secondButton"
                      android:layout_alignParentTop="true" android:background="@drawable/btn_second_off"
                      android:layout_height="43dp" android:layout_width="100dp"
                      android:clickable="true"></Button>
                  <Button android:id="@+id/thirdButton"
                      android:layout_alignParentTop="true" android:background="@drawable/btn_third_off"
                      android:layout_height="43dp" android:layout_width="100dp"
                      android:clickable="true"></Button>
                  <Button android:id="@+id/forthButton"
                      android:layout_alignParentTop="true" android:background="@drawable/btn_forth_off"
                      android:layout_height="43dp" android:layout_width="100dp"
                      android:clickable="true"></Button>
              </LinearLayout>
      
              <FrameLayout android:id="@android:id/tabcontent"
                  android:layout_width="fill_parent" android:layout_height="fill_parent"
                  android:layout_below="@+id/tabbar" />
      
          </RelativeLayout>
      </TabHost>
      
    2. Set up the onCreate of your activity to handle using the buttons for adjusting the tab views:

          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.main);
      
              // tabs        
              firstButton = (Button) findViewById(R.id.firstButton);
              secondButton = (Button) findViewById(R.id.secondButton);        
              thirdButton = (Button) findViewById(R.id.thirdButton);
              forthButton = (Button) findViewById(R.id.forthButton);
      
              Resources res = getResources(); // Resource object to get Drawables
              final TabHost tabHost = getTabHost();  // The activity TabHost
              TabHost.TabSpec spec;  // Resusable TabSpec for each tab
              Intent intent;  // Reusable Intent for each tab
      
              intent = new Intent().setClass(this, FirstGroupActivity.class);
              spec = tabHost.newTabSpec("first").setIndicator("First").setContent(intent);
              tabHost.addTab(spec);
              intent = new Intent().setClass(this, SecondGroupActivity.class);
              spec = tabHost.newTabSpec("second").setIndicator("Second").setContent(intent);
              tabHost.addTab(spec);   
      
              intent = new Intent().setClass(this, ThirdGroupActivity.class);
              spec = tabHost.newTabSpec("third").setIndicator("Third").setContent(intent);
              tabHost.addTab(spec);
      
      
              intent = new Intent().setClass(this, ForthActivity.class);
              spec = tabHost.newTabSpec("forth").setIndicator("Forth").setContent(intent);
              tabHost.addTab(spec);
      
      
              tabHost.setCurrentTab(0);
      
              firstButton.setOnClickListener(new OnClickListener() {
      
                  public void onClick(View v)
                  {
                      tabHost.setCurrentTab(0);
                      firstButton.setBackgroundResource(R.drawable.btn_first_on);
                      secondButton.setBackgroundResource(R.drawable.btn_second_off);              
                      thirdButton.setBackgroundResource(R.drawable.btn_third_off);
                      forthButton.setBackgroundResource(R.drawable.btn_forth_off);            
                  }
      
              });
      
      
              secondButton.setOnClickListener(new OnClickListener() {
      
                  public void onClick(View v)
                  {
                      tabHost.setCurrentTab(1);
                      firstButton.setBackgroundResource(R.drawable.btn_first_off);
                      secondButton.setBackgroundResource(R.drawable.btn_second_on);                       
                      thirdButton.setBackgroundResource(R.drawable.btn_third_off);                        
                      forthButton.setBackgroundResource(R.drawable.btn_forth_off);
      
                  }
      
              });
      
      
              thirdButton.setOnClickListener(new OnClickListener() {
      
                  public void onClick(View v)
                  {
                      tabHost.setCurrentTab(3);
                      firstButton.setBackgroundResource(R.drawable.btn_first_off);
                      secondButton.setBackgroundResource(R.drawable.btn_second_off);              
                      thirdButton.setBackgroundResource(R.drawable.btn_third_on);
                      forthButton.setBackgroundResource(R.drawable.btn_forth_off);
      
                  }
      
              });
      
      
              forthButton.setOnClickListener(new OnClickListener() {
      
                  public void onClick(View v)
                  {
                      tabHost.setCurrentTab(4);
                      firstButton.setBackgroundResource(R.drawable.btn_first_off);
                      secondButton.setBackgroundResource(R.drawable.btn_second_off);              
                      thirdButton.setBackgroundResource(R.drawable.btn_third_off);
                      forthButton.setBackgroundResource(R.drawable.btn_forth_on);
      
                  }
      
              });
          }
      

    As you can see, I’m using drawables for the images of the buttons on and off. Using this technique, you’re not limited to the options available when simply just trying to customize the look of the TabWidget’s tabs and you can create a completely custom look to your tabs.

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

Sidebar

Related Questions

I know we already have many posts about this topic, but I just cannot
I was just reading a blog post about sanitizing user input in Ruby before
Before answering this question, understand that I am not asking how to create my
If this has been asked before, I apologize but this is kinda of a
I want to know something about this article In order to create custom post
i have previously posted about triggering a dialog box before confirming a submit. But,
This is a follow up to my previous question about using XMLHttpRequest() to post
I read this comment in the OpenID post on the stackoverflow blog. Kibbee says
I have a problem with this is code: Set oXmlHTTP = CreateObject(Microsoft.XMLHTTP) oXmlHTTP.Open POST,
I need from one JSP open another JSP, and send POST parameters to this

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.