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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:51:37+00:00 2026-05-26T13:51:37+00:00

[Solution at the bottom] I need a tab to have the following behaveyour but

  • 0

[Solution at the bottom]

I need a tab to have the following behaveyour but am not sure how to implement it:

  • The tabs need to be at the bottom.
  • The tabs need an icon & text.
  • Each icon needs to be different.
  • The icon needs to change colour when selected and the tab needs an overlay.

The reason I’m asking so vaguely is that I’ve tried implementing one way but hit a brick wall so I’m wondering how the more experienced would go about it.

Some source as requested:
CustomTabActivity.java

private TabHost mTabHost;
private Context ctx = this;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // construct the tabhost
    setContentView(R.layout.main);

    setupTabHost();
    mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
    setupTab(new TextView(this), "t1", R.drawable.myimg1);
    setupTab(new TextView(this), "t2", R.drawable.myimg2);
    mTabHost.setOnTabChangedListener(new OnTabChangeListener(){

        @Override
        public void onTabChanged(String tabId) {
            Log.e("Simon", "Current tab - " + Integer.toString(mTabHost.getCurrentTab()));
            View currentView = mTabHost.getChildAt(mTabHost.getCurrentTab());
            currentView.getClass();
        }

    });
}

private void setupTabHost() {
    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();
}

private void setupTab(final View view, final String tag, int num) {
    View tabview = createTabView(mTabHost.getContext(), tag, num);

    TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
        public View createTabContent(String tag) {return view;}
    });
    mTabHost.addTab(setContent);
}

private static View createTabView(final Context context, final String text, final int num) {
    View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
    TextView tv = (TextView) view.findViewById(R.id.tabsText);
    tv.setText(text);

    ImageView iv = (ImageView) view.findViewById(R.id.tabsImg);

    iv.setImageResource(num);
    return view;
}

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <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">
            <FrameLayout android:id="@android:id/tabcontent"
                android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1">
                <ViewStub android:id="@+id/stub1"
                   android:inflatedId="@+id/subTree"
                   android:layout="@layout/mylayout"
                   android:layout_width="fill_parent"
                   android:layout_height="fill_parent" />
            </FrameLayout>
            <TabWidget android:id="@android:id/tabs" 
                android:layout_width="fill_parent" android:background="@drawable/tabs_bg" android:layout_height="wrap_content"/>
        </LinearLayout>
    </TabHost>

</LinearLayout>

mylayout.xml

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="?android:attr/progressBarStyleLarge" android:id="@+id/progressBar1"></ProgressBar>

</LinearLayout>

————–Solution————-

So the issue is solved. I’ve replaced the R.drawable.myimg1 from being a static image in the res/drawable-[hdpi|ldpi|mdpi] folders and replaced it with a new xml file in res/drawable that looks like this:

mydrawable1.xml

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

Where myimg1 and myimg1_selected are the images I want shown in different states.

  • 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-26T13:51:38+00:00Added an answer on May 26, 2026 at 1:51 pm

    Check this tutorial. It describes how to change icon if tab is selected.

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

Sidebar

Related Questions

Any Solution ? I have looked into many solution but not worked. for example
I need to develop an app with tab bar on the bottom, but I
I'm trying to find a solution for the following mechanism: I have a bottom
Intro: EDIT: See solution at the bottom of this question (c++) I have a
Solution: Make sure nothing is null! I have a ListView throwing a NullPointerException, and
I need a webView inside a tab, should be an easy task but I
I have a page where I need a piece of text to appear aligned
I need to keep a footer on bottom, but its height is variable so
In my application I have a tab bar. It contains four tabs in which
I need some help in picking the 'right' solution for the following 'problem'. I

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.