0

I have three tabs on my android application ,Now i am using text for three tabs,I want to replace icon from text( invitation , event , group chat ). My layout code is given,

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.app.FragmentTabHost 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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">


        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="-4dp"
            android:layout_weight="0" />
    </LinearLayout>

</android.support.v4.app.FragmentTabHost>

here having setindicator as a string but i want to remove the text and replace the icons

My activity code is given below ,

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_dash_board);
        context = getApplicationContext();
        sharedpreferences = context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME,
                Context.MODE_PRIVATE);

        tabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
        tabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);

        tabHost.addTab(tabHost.newTabSpec(TAB_1_TAG).setIndicator("Invitation"),InvitationFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec(TAB_2_TAG).setIndicator("Event"), OccasionFragment.class, null);
        tabHost.addTab(tabHost.newTabSpec(TAB_3_TAG).setIndicator("GroupChat"), GroupChatFragment.class, null);



        tabHost.getTabWidget().setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.ic_action_person);*/
        //invitation tab highlighted by default
        tabHost.getTabWidget().setCurrentTab(0);
        tabHost.getTabWidget().getChildAt(0).setBackgroundColor(getResources().getColor(R.color.Orange));
        tabHost.getTabWidget().getChildAt(1).setBackgroundColor(getResources().getColor(R.color.scandal));
        tabHost.getTabWidget().getChildAt(2).setBackgroundColor(getResources().getColor(R.color.scandal));

1 Answers1

0

Try this

  tabHost.addTab(tabHost
 .newTabSpec("one")
 .setIndicator("The Tab",res.getDrawable(R.drawable.yourxmlfile))
 .setContent(new Intent(this, YourClass.class)));

Reference How to change the Tabs Images in the TabHost

Good Luck

Community
  • 1
  • 1
Shubhank Gupta
  • 833
  • 2
  • 15
  • 35
  • thank you for your response when i am trying this code i am getting error for "res" Qualifier must be an expression i could not find why. i searched about tabhost but they were created three separate xml files here it has having single xml how can i add icons for that ? – sathya chinnasamy Nov 21 '15 at 11:33
  • no idea brother but i recently used the tabhost at my project if you want so i can give the link actually there i am using the three fragments and one activity – Shubhank Gupta Nov 21 '15 at 11:35
  • can you please paste the link – sathya chinnasamy Nov 21 '15 at 12:08