We have a strange problem concerning a TabHost-widget in Android. How can we fix the pixel-Line error (shown on the image below):
Thanks for your help.
I also have Same problem before some days. But now got solution with changing it to images.
By Default First Tab is selected and when the Tab Getting change the all tab get changed automatically based on the Tab Selection.
See below Code:
public class MainTabActivity extends TabActivity {
TabHost mTabHost;
TabWidget mTabWidget;
private TextView title;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_tab_layout);
//Resources res = getResources();
mTabHost = getTabHost();
TabHost.TabSpec spec;
mTabWidget = mTabHost.getTabWidget();
Intent intent;
intent = new Intent().setClass(MainTabActivity.this, TodaysDealsGroupActivity.class);
spec = mTabHost.newTabSpec(getResources().getString(R.string.tab_todays_deal)).setIndicator(getResources().getString(R.string.tab_todays_deal), getResources().getDrawable(R.drawable.tab_loyalshop_selector)).setContent(intent);
mTabHost.addTab(spec);
intent = new Intent().setClass(MainTabActivity.this, BuddiesGroupActivity.class);
spec = mTabHost.newTabSpec(getResources().getString(R.string.tab_buddies)).setIndicator(getResources().getString(R.string.tab_buddies), getResources().getDrawable(R.drawable.tab_buddies_selector)).setContent(intent);
mTabHost.addTab(spec);
intent = new Intent().setClass(MainTabActivity.this, SearchGroupActivity.class);
spec = mTabHost.newTabSpec(getResources().getString(R.string.tab_search)).setIndicator(getResources().getString(R.string.tab_search), getResources().getDrawable(R.drawable.tab_search_selector)).setContent(intent);
mTabHost.addTab(spec);
intent = new Intent().setClass(MainTabActivity.this, ProfileGroupActivity.class);
spec = mTabHost.newTabSpec(getResources().getString(R.string.tab_profile)).setIndicator(getResources().getString(R.string.tab_profile), getResources().getDrawable(R.drawable.tab_profile_selector)).setContent(intent);
mTabHost.addTab(spec);
intent = new Intent().setClass(MainTabActivity.this, NotificationsGroupActivity.class);
spec = mTabHost.newTabSpec(getResources().getString(R.string.tab_notifications)).setIndicator(getResources().getString(R.string.tab_notifications), getResources().getDrawable(R.drawable.tab_notification_selector)).setContent(intent);
mTabHost.addTab(spec);
for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
mTabHost.getTabWidget().getChildAt(i).setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_black_bg));
title = (TextView) mTabWidget.getChildAt(i).findViewById(android.R.id.title);
title.setTextColor(Color.WHITE);
title.setTextSize(10);
}
// check if App starts from the Notification click or not
if(getIntent().hasExtra("notification")){
// for the current tab selection
mTabHost.getTabWidget().getChildAt(4).setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_blue_bg));
mTabHost.setCurrentTab(4);
title = (TextView) mTabWidget.getChildAt(4).findViewById(android.R.id.title);
}else{
// for the current tab selection
mTabHost.getTabWidget().getChildAt(0).setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_blue_bg));
mTabHost.setCurrentTab(0);
title = (TextView) mTabWidget.getChildAt(0).findViewById(android.R.id.title);
}
title.setTextColor(Color.BLACK);
title.setTextSize(10);
// listener for the tab changed
mTabHost.setOnTabChangedListener(new OnTabChangeListener() {
#Override
public void onTabChanged(String tabId) {
for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {
mTabHost.getTabWidget().getChildAt(i).setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_black_bg));
title = (TextView) mTabWidget.getChildAt(i).findViewById(android.R.id.title);
title.setTextColor(Color.WHITE);
title.setTextSize(10);
}
int tab = mTabHost.getCurrentTab();
mTabHost.getTabWidget().getChildAt(tab).setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_blue_bg));
title = (TextView) mTabWidget.getChildAt(tab).findViewById(android.R.id.title);
title.setTextColor(Color.BLACK);
title.setTextSize(10);
}
});
}
}
And here is the XMl file main_tab_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
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="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom|center_horizontal"
android:tabStripEnabled="false" >
</TabWidget>
</LinearLayout>
</TabHost>
</LinearLayout>
Just Replace with your images and See the Result.
Hope this will help you a lot as it help me.
Enjoy Coding...
I have three tabs and a custom divider, however a custom xml (customtabview.xml) is used for all five tabs.
Tabs.java
tabHost = getTabHost();
TabHost.TabSpec spec;
LinearLayout v = (LinearLayout)(getLayoutInflater().inflate(R.layout.customtabview, null));
//FIRST TAB
((TextView)v.findViewById(R.id.title)).setText("FIRST");
((TextView)v.findViewById(R.id.title)).setCompoundDrawablesWithIntrinsicBounds(0,R.drawable .tab_back,0,0 );
spec = tabHost.newTabSpec("first").setIndicator(v).setContent(R.id.tab_first_info);
tabHost.addTab(spec);
//SECOND TAB
((TextView)v.findViewById(R.id.title)).setText("SECOND");
((TextView)v.findViewById(R.id.title)).setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_back,0,0 );
spec = tabHost.newTabSpec("second").setIndicator(v).setContent(R.id.tab_second_info);
tabHost.addTab(spec);
//THIRD TAB
((TextView)v.findViewById(R.id.title)).setText("THIRD");
((TextView)v.findViewById(R.id.title)).setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.tab_back,0,0 );
spec = tabHost.newTabSpec("third").setIndicator(v).setContent(R.id.tab_third_info);
tabHost.addTab(spec);
customtabview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >
<TextView
android:id="#+id/title"
android:drawablePadding="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Related
What i want to do : I want to make exactly like below :
i managed to do something like below :
Code:
ISSUE : i want to following things :
i want to add divider the same in above picture .
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 .
i have working with tabs. i want to change the background color or theme for tab. when i click on the tab appears in default color as grey but i want to display that tab in custom color.
here my code:
<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"
android:orientation="vertical"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="-30dp"
android:background="#FF0000"
/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</FrameLayout>
</LinearLayout>
</TabHost>
class file is
public class AndroidtabActivity extends TabActivity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// View title = getWindow().findViewById(android.R.id.title);
// View titleBar = (View) title.getParent();
// titleBar.setBackgroundResource(R.drawable.top_bar2);
Resources res = getResources();
TabHost tabHost = getTabHost();
//tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup();
//tabHost.setBackgroundResource(R.drawable.pink);
TabHost.TabSpec spec;
//tabHost.getTabWidget().setDividerDrawable(R.drawable.top_bar);
Intent in;
in = new Intent().setClass(this, MainActivity.class);
spec=tabHost.newTabSpec("calc").setIndicator("calculate").setContent(in);
tabHost.addTab(spec);
in = new Intent().setClass(this, TutorialZoomActivity1.class);
spec=tabHost.newTabSpec("help").setIndicator("help").setContent(in);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
// spec1.setIndicator("Tab 1",getResources().getDrawable(R.drawable.flash));
}
}
please tell me how can i change the background color for tabs.
Maybe you should create your custom tab.
Let say.. create another custom_tab.xml (linearlayout and textview)
in the linearlayout, set android:background to another xml file in the drawable (#drawable/tab_selector)
Create new xml file in the drawable just mention above. ex. tab_selector.xml. in this file, you can set state (focused, pressed, selected etc) good luck
You can change tab background color by
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).
setBackgroundResource(R.drawable.hans_layout_nblue);
}
in android tutorial there isn't a way for customize tab background. my app is official-tutorial based..can anyone help me with a tutorial or code for backgroundcolor white?
this is my code:
LauncherActivity.java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launcher);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, MyActivity.class);
spec = tabHost.newTabSpec("myactivity").setIndicator("Activity")
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, search.class);
spec = tabHost.newTabSpec("search").setIndicator("Search"
)
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MyActivity3.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs"
)
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
Launcher.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="[url]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"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="0dp" />
</LinearLayout>
</TabHost>
If you mean to change background color of tabs,then here is the code:
for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
{
tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.WHITE); //unselected tab
}
for selected tab,
tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.GRAY); // selected tab
You can put above lines into a method (say setTabColors()) and call it:
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
#Override
public void onTabChanged(String arg0) {
setTabColors(tabHost);
}
});
how can i Reduce Tab height and align text on top?
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
public class MessagesTabs extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.messages_tabs);
//Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, GetMessages.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("inbox").setIndicator("Inbox")
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, GetConversations.class);
spec = tabHost.newTabSpec("conversation").setIndicator("Conversation")
.setContent(intent);
tabHost.addTab(spec);
/*
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);*/
tabHost.setCurrentTab(0);
}
}
xmlfile
<?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"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</TabHost>
just try this for increasing the height of the tabs :
tabHost.getTabWidget().getChildAt(index).getLayoutParams().height =(int) height;
for text aligning try this in your xml layout :
android:gravity="top" or android:layout_gravity="top"
use this code. It may work for you:
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
tabHost.getTabWidget().getChildAt(i).getLayoutParams().height /= 2;
}
You need to create a custom layout for your tab, inflate it and use setIndicator
I have created a tab in my app. Now the thing is that when I set the background color of my tab to white it's working but only grey color underline still appears so can anyone tell me how can I remove that line?
I am sending my code and snapshot of where the underline arise.
Code for XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:background="#FFFFFF">
<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"
android:background="#FFFFFF">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</LinearLayout>
</TabHost>
</LinearLayout>
Code for java:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost MainTabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, ContactListForm.class);
spec = MainTabHost.newTabSpec("Contacts").setIndicator("Contacts",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
MainTabHost.addTab(spec);
intent = new Intent().setClass(this, CallDialerForm.class);
spec = MainTabHost.newTabSpec("Call").setIndicator("Call",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
MainTabHost.addTab(spec);
intent = new Intent().setClass(this, MyInfoForm.class);
spec = MainTabHost.newTabSpec("My Info").setIndicator("MyInfo",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
MainTabHost.addTab(spec);
MainTabHost.setCurrentTab(0);
for (int j = 0; j < MainTabHost.getTabWidget().getChildCount(); j++)
{
MainTabHost.getTabWidget().getChildAt(j).setBackgroundColor(Color.parseColor("#FFFFFF"));
}
}
Snapshot:
Use this in your code where you setup tabs. Mind you it is supported only from SDK 8 onwards.
if(7 < Build.VERSION.SDK_INT){
tabHost.getTabWidget().setStripEnabled(false);
}
I was also same type of problem but i have removed it using the fallowing blow given code
tabHost = getTabHost(); // The activity TabHost
tabHost.setOnTabChangedListener(this);
Resources res = getResources(); // Resource object to get Drawables
tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
TabSpec fourthTabSpec = tabHost.newTabSpec("tid4");
TabSpec fifthTabSpec = tabHost.newTabSpec("tid5");
viewCache[0] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
viewCache[1] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
viewCache[2] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
viewCache[3] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
viewCache[4] = LayoutInflater.from(this).inflate(R.layout.tabs1, null);
firstTabSpec.setIndicator(viewCache[0]);
secondTabSpec.setIndicator(viewCache[1]);
thirdTabSpec.setIndicator(viewCache[2]);
fourthTabSpec.setIndicator(viewCache[3]);
fifthTabSpec.setIndicator(viewCache[4]);
firstTabSpec.setContent(new Intent(this, HomeTabActivityGroup.class));
secondTabSpec
.setContent(new Intent(this, ProfileTabActivityGroup.class));
thirdTabSpec.setContent(new Intent(this,
NotificationTabActivityGroup.class));
fourthTabSpec.setContent(new Intent(this,
FavoritesTabActivityGroup.class));
fifthTabSpec
.setContent(new Intent(this, MoreTabActivityGroupNew.class));
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thirdTabSpec);
tabHost.addTab(fourthTabSpec);
tabHost.addTab(fifthTabSpec);
currentTabvalue = tabHost.getCurrentTab();
C2DMessaging.register(TennisAppActivity.mContext,
"racquetester#gmail.com");
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
// tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#7392B5"));
switch (i) {
case 0:
tabHost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.home);
break;
case 1:
tabHost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.profile);
break;
case 2:
tabHost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.notifications);
break;
case 3:
tabHost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.fav);
break;
case 4:
tabHost.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.more);
break;
}
}
//***************************************************
it is the xml file use for it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android" android:gravity="center">
<ImageView android:id="#+id/ImageView01" android:layout_width="wrap_content" android:layout_height="50dip"></ImageView>
I hope it is help full to you.