1

What i want to do : I want to make exactly like below :

enter image description here

i managed to do something like below :

enter image description hereCode:

ISSUE : i want to following things :

  1. i want to add divider the same in above picture .
  2. i want to remove the space between the icon and text . Also want my icon in centre .

Following is code :

Tab.xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/transparent"

    >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
          android:background="@android:color/white"

     >
     <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
              android:background="@android:color/white"


            />
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:showDividers="middle"
              android:background="@color/button_color"
            android:tabStripEnabled="false"


             />

    </LinearLayout>
</TabHost>

TabActivity.class

  public class MainActivity extends TabActivity {

        protected static Context context;
        TabHost tabHost; 
        SharedPreferences mpref;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
             setContentView(R.layout.activity_main);

            context = getApplicationContext();
               // TabHost tabHost = getTabHost();
                tabHost = getTabHost(); 
                SharedPreferences preferences2 = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
                String u_id1 = preferences2.getString("Userid","");
                Bean b = new Bean();
                b.setDeviceid(u_id1);

               // tabHost.getTabWidget().getResources().getDrawable(R.drawable.tab); 
             // Tab for Photos
                TabSpec photospec = tabHost.newTabSpec("Favourite");
                photospec.setIndicator("Favorites", getResources().getDrawable(R.drawable.tab_favourites));

                Intent photosIntent = new Intent(this, Favourite.class);
                photospec.setContent(photosIntent);

                // Tab for Songs
                TabSpec songspec = tabHost.newTabSpec("Contacts");
                // setting Title and Icon for the Tab

                songspec.setIndicator("Contacts", getResources().getDrawable(R.drawable.tab_contacts));
                Intent songsIntent = new Intent(this, Contacts.class);
                songspec.setContent(songsIntent);

                // Tab for Videos
                TabSpec videospec = tabHost.newTabSpec("Meeting");
                videospec.setIndicator("Meeting",getResources().getDrawable(R.drawable.tab_meeting));
                Intent videosIntent = new Intent(this, Meeting.class);
                videospec.setContent(videosIntent);
             // Tab for Future SMS
                TabSpec futuresms = tabHost.newTabSpec("Map");
                futuresms.setIndicator("Map",getResources().getDrawable(R.drawable.tab_map));
                Intent futureIntent = new Intent(this, Map.class);
                futuresms.setContent(futureIntent);
                // Tab for Future SMS
                TabSpec setting = tabHost.newTabSpec("Setting");
                setting.setIndicator("Setting",getResources().getDrawable(R.drawable.tab_setting));
                Intent settingintent = new Intent(this, Setting.class);
                setting.setContent(settingintent);

            tabHost.getTabWidget().setDividerDrawable(R.color.dividerColor);

            // Adding all TabSpec to TabHost
                tabHost.addTab(photospec); // Adding photos tab
                tabHost.addTab(songspec); // Adding songs tab
                tabHost.addTab(videospec); // Adding videos tab
                tabHost.addTab(futuresms);
                tabHost.addTab(setting);
    //          tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_favourites);
    //          tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.tab_contacts);
    //          tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.tab_meeting);
    //          tabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.tab_map);
    //          tabHost.getTabWidget().getChildAt(4).setBackgroundResource(R.drawable.tab_setting);




            int k = tabHost.getTabWidget().getTabCount();
            for (int j=0;j<tabHost.getTabWidget().getChildCount();j++){
                TextView textView = (TextView)tabHost.getTabWidget().getChildAt(j).findViewById(android.R.id.title);
                textView.setTextSize(10);

            }


            for (int i = 0; i <tabHost.getTabWidget().getChildCount(); i++) {
                tabHost.getTabWidget().getChildTabViewAt(i).setBackgroundColor(getResources().getColor(R.color.button_color));

            }
    //      ((TextView)tabHost.getChildAt(2).findViewById(android.R.id.title)).setTextSize(10);
    //      ((TextView)tabHost.getChildAt(3).findViewById(android.R.id.title)).setTextSize(10);
    //      ((TextView)tabHost.getChildAt(4).findViewById(android.R.id.title)).setTextSize(10);
    //      tv.setTextSize(20);

  tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.tab_click);


                int in = Integer.parseInt(tabid);
                tabHost.setCurrentTab(in);
               }



             }

Please help me to achieve this either by some other approach or some snippet .

young_08
  • 1,196
  • 2
  • 13
  • 35
  • As for the divider, can you try adding `android:divider="@color/white"`? AS for the other demand, I am helpless except for googling out [this similar question](http://stackoverflow.com/questions/30568749/how-can-remove-padding-or-margin-in-tabwidget-in-android). It even has a nifty little drawing :) – Vucko Jun 25 '16 at 19:31
  • @Vucko : no its not working – young_08 Jun 25 '16 at 19:34
  • How about [this](http://stackoverflow.com/questions/9523083/tab-dividers-not-showing-in-ics) question – Vucko Jun 25 '16 at 19:36
  • @Vucko i have tried the above link , it worked for the image selection/unselection but textcolor is not coming the way i want it according yo this – young_08 Jun 28 '16 at 18:35

0 Answers0