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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:53:09+00:00 2026-05-27T10:53:09+00:00

My main activity is a TabActivity , but my tabs don’t require icons. I

  • 0

My main activity is a TabActivity, but my tabs don’t require icons. I know I can omit the icon by using the overloaded TabHost.TabSpec.setIndicator(CharSequence label) method, as answered in this question.

But the space where the icon would go is still reserved, so a lot of space is wasted. This has already been remarked in this question. It seems I can’t just reduce the tab height. I’ll have to supply my own View with the TabHost.TabSpec.setIndicator(View view) overload.

Fine, but I want to make sure the rest of the styling (background/coloring) remains consistently ‘android’ across all devices, just as if I’d used a default tab indicator. So I don’t want to supply my own colors.

I’ve found @android:color/tab_indicator_text and using it for the TextViews text-color seems to work as expected. But I don’t know where to get the default tab-background-colors. I’ve also discovered the @android:style/Widget.TabWidget style, but applying it to neither the TextView nor the surrounding LinearLayout seems to help.

This is my tab indicator view xml file, taken from some tutorial:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:padding="12dip" >

    <TextView
        android:id="@+id/tabText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/tab_indicator_text" />
</LinearLayout>

How do I get ‘android default’ tab styling on this?


Edit: Next, I tried to add a default tab through setIndicator(CharSequence), take the getBackground drawable of its indicator view, clear all tabs, add my custom views (see above), then put the drawable I retrieved in setBackground for the new indicators.

The result looks sort of right and sort of wrong. For one, they’re too high again, so I gained nothing. For another, the background states of all tabs are now linked somehow (active, highlighted, selected, etc.). Using mutate() on the drawable(s) didn’t help at all. Next trick: I added three default tabs, took all of their backgrounds, cleared them, and gave my own three tabs one background each.

Well, that solves the second problem. Their states are no longer linked. But they’re still too high. So I reduced the height of the TabWidget using updateViewLayout. This works, but leaves a discolored bar at the top of the tab indicators.

Actually, I just end up with the same situation as when using the TabHost.TabSpec.setIndicator(CharSequence label) method. And anyway, all these hacks make me feel dirty. Isn’t there an elegant way to get default android styling on a custom view?

  • 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-27T10:53:09+00:00Added an answer on May 27, 2026 at 10:53 am

    This code taken from android sources tab_indicator.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="0dip"
        android:layout_height="64dip"
        android:layout_weight="1"
        android:layout_marginLeft="-3dip"
        android:layout_marginRight="-3dip"
        android:orientation="vertical"
        android:background="@android:drawable/tab_indicator">
    
        <ImageView android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
        />
    
        <TextView android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            style="?android:attr/tabWidgetStyle"
        />
    
    </RelativeLayout>
    

    You can try to just take this code, delete the ImageView, change layout_centerHorizontal in the TextView to layout_center, reduce height of the RelativeLayout, and provide this view in TabHost.TabSpec.setIndicator(View view). There are references only to @android resources, so you do not need create any drawables or text styles.

    EDIT

    The standard android drawable background for the tab indicator is not visible from an app, but it is possible to do it like this:

    TabSpec tc = getTabHost().newTabSpec("tag");
    tc.setIndicator("indicator1");
    tc.setContent(content);
    getTabHost().addTab(tc);
    getTabHost().findViewById(android.R.id.icon).setVisibility(View.GONE);
    TextView tv = (TextView) getTabHost().findViewById(android.R.id.title);
    RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    rllp.addRule(RelativeLayout.CENTER_IN_PARENT);
    tv.setLayoutParams(rllp);
    

    Then it is possible to reduce the height of the tabs:

    RelativeLayout parent = ((RelativeLayout) tv.getParent());
    ViewGroup.LayoutParams vglp = parent.getLayoutParams();
    vglp.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
    parent.setLayoutParams(vglp);
    

    The result will be: this

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

Sidebar

Related Questions

Newb question. How can you know what the main launch Activity is? Learning Android.
I tried using the following code in .java(main activity): final ImageView diskView1 = (ImageView)
For tracking user activity, I am using a Windows Hook for the main application
I currently have this code that creates 4 tabs using tabactivity: public class toknapp
I need a little help.I'm using a ViewFlipper to change views in TabActivity but
I have a Main TabActivity with 5 tabs on it. Each tabs consists of
Mi main activity is a TabActivity that launches an intent TabGroup activity, this tabGroup
My main activity is a TabActivity. I have some activities presented by the tab
In the following app the tabs will show correctly but I can't determine why
I have an Android application which has four tabs (I use a main TabActivity

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.