public static void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) { tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#FF0000")); //unselected } tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#0000FF")); // selected }
TabHost tabhost = getTabHost(); for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) { TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(.....); }
TabHost tabhost = getTabHost(); for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) { TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(Color.parseColor("#000000")); }
private View createIndicatorView(TabHost tabHost, CharSequence label, Drawable icon) { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View tabIndicator = inflater.inflate(R.layout.tab_indicator, tabHost.getTabWidget(), // tab widget is the parent false); // no inflate params final TextView tv = (TextView) tabIndicator.findViewById(R.id.title); tv.setText(label); final ImageView iconView = (ImageView) tabIndicator.findViewById(R.id.icon); iconView.setImageDrawable(icon); return tabIndicator; }
TabHost host = (TabHost)view.findViewById(R.id.tab_host); TabWidget widget = host.getTabWidget(); for(int i = 0; i < widget.getChildCount(); i++) { View v = widget.getChildAt(i); // Look for the title view to ensure this is an indicator and not a divider. TextView tv = (TextView)v.findViewById(android.R.id.title); if(tv == null) { continue; } v.setBackgroundResource(R.drawable.your_tab_selector_drawable); }
@Implementation protected TabWidget getTabWidget() { return getTabHost().getTabWidget(); } }
setContentView(R.layout.main_view); final TabHost tabHost = (TabHost) findViewById(R.id.tabHost); tabHost.setup(); Resources res = getResources(); Configuration cfg = res.getConfiguration(); boolean hor = cfg.orientation == Configuration.ORIENTATION_LANDSCAPE; if (hor) { TabWidget tw = tabHost.getTabWidget(); tw.setOrientation(LinearLayout.VERTICAL); }
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 140; tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 140; tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 140; tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 140; tabHost.getTabWidget().getChildAt(4).getLayoutParams().width = 140;
@Test public void shouldGetTabWidget() throws Exception { TabActivity activity = Robolectric.buildActivity(TabActivity.class).create().get(); activity.setContentView(R.layout.tab_activity); TabHost host = new TabHost(activity); assertThat(host.getTabWidget()).isInstanceOf(TabWidget.class); } }
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); tabHost.getTabWidget().getChildAt(0).setVisibility(View.GONE);
...onCreate(){ ... tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String arg0) { setTabColor(tabHost); } }); setTabColor(tabHost); ... } //Change The Backgournd Color of Tabs public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) tabhost.getTabWidget().getChildAt(i).setBackgroundColor(COLOR_CYAN); //unselected if(tabhost.getCurrentTab()==0) tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_RED); //1st tab selected else tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(COLOR_BLUE); //2nd tab selected }
Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); TabHost mTabHost = getTabHost(); mTabHost.addTab(mTabHost.newTabSpec("tab_test1") .setIndicator((""),getResources().getDrawable(R.drawable.mzl_05)) .setContent(new Intent(this, NearBy.class))); mTabHost.addTab(mTabHost.newTabSpec("tab_test2") .setIndicator((""),getResources().getDrawable(R.drawable.mzl_08)) .setContent(new Intent(this, SearchBy.class))); mTabHost.setCurrentTab(0); mTabHost.getTabWidget().getChildAt(0).setLayoutParams(new LinearLayout.LayoutParams((width/2)-2,50)); mTabHost.getTabWidget().getChildAt(1).setLayoutParams(new LinearLayout.LayoutParams((width/2)-2,50));
/** * Opens a brand new browser tab. * * @param directory The directory to open when this tab is initialized. */ protected BaseLayoutView openNewBrowserTab(File directory) { //Inflate the view's layout based on the selected layout. BaseLayoutView contentView = null; if (mFileBrowserView.getFileBrowserLayoutType() == FileBrowserView.FILE_BROWSER_LIST_LAYOUT) contentView = new ListLayoutView(mContext, mFileBrowserView.getAttributeSet(), mFileBrowserView).init(mTabContentLayout); contentView.setId(mTabHost.getTabWidget().getTabCount() + 1); mTabContentLayout.addView(contentView); //Add the new tab to the TabHost. String directoryName = directory.getAbsoluteFile().getName(); TabHost.TabSpec newTabSpec = mTabHost.newTabSpec(directoryName); newTabSpec.setIndicator(directoryName); newTabSpec.setContent(mTabHost.getTabWidget().getTabCount() + 1); mTabHost.addTab(newTabSpec); return contentView; }
// light theme support final TabHost tabHost = getTabHost(); tabHost.setBackgroundColor(Color.WHITE); tabHost.getTabWidget().setBackgroundColor(Color.BLACK); // hack to set font size LinearLayout ll = (LinearLayout) tabHost.getChildAt(0); TabWidget tw = (TabWidget) ll.getChildAt(0); // first tab RelativeLayout rllf = (RelativeLayout) tw.getChildAt(0); lf = (TextView) rllf.getChildAt(1); lf.setTextSize(21); lf.setPadding(0, 0, 0, 6); // second tab RelativeLayout rlrf = (RelativeLayout) tw.getChildAt(1); rf = (TextView) rlrf.getChildAt(1); rf.setTextSize(21); rf.setPadding(0, 0, 0, 6);
public void setTabColor(TabHost tabhost) { for(int i=0;i<tabhost.getTabWidget().getChildCount();i++) { tabhost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg); //unselected } }
public static void setTabColor(TabHost tabhost) { for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) { tabhost.getTabWidget().getChildAt(i) .setBackgroundResource(R.drawable.header_blank); // unselected } tabhost.getTabWidget().setCurrentTab(0); tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()) .setBackgroundResource(R.drawable.tab_selected_new); // selected // //have // to // change }
setTabIcon(mTabHost, 0, R.drawable.ic_tab1); //for Tab 1 setTabIcon(mTabHost, 1, R.drawable.ic_tab2); //for Tab 2 public void setTabIcon(TabHost tabHost, int tabIndex, int iconResource) { ImageView tabImageView = (ImageView) tabHost.getTabWidget().getChildTabViewAt(tabIndex).findViewById(android.R.id.icon); tabImageView.setVisibility(View.VISIBLE); tabImageView.setImageResource(iconResource); }
public void addNewTab(Context context, String title, int height){ TabHost tabHost = getTabHost(); // The activity TabHost Intent intent = new Intent().setClass(context, HelloTabsActivity.class); TabHost.TabSpec spec = tabHost.newTabSpec(title.toLowerCase()).setIndicator(title).setContent(intent); tabHost.addTab(spec); int totalTabs = tabHost.getTabWidget().getChildCount(); ((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).removeViewAt(0); ((TextView)((RelativeLayout)tabHost.getTabWidget().getChildTabViewAt(totalTabs-1)).getChildAt(0)).setHeight(30); tabHost.getTabWidget().getChildAt(totalTabs-1).getLayoutParams().height = height; }
TabHost tabHost = getTabHost(); public void onResume() { super.onResume(); tabHost.getTabWidget().getChildAt(0).setOnClickListener(new OnClickListener() { public void onClick(View v) { count++; tabHost.setCurrentTab(0); //based on your count value..you can do anything...like going back to homepage... // similar thing exist on iphone (double tab a tab..it takes back to homepage) } }); }
TabHost host = (TabHost)view.findViewById(R.id.tab_host); TabWidget widget = host.getTabWidget(); for(int i = 0; i < widget.getChildCount(); i++) { View v = widget.getChildAt(i); // Look for the title view to ensure this is an indicator and not a divider. TextView tv = (TextView)v.findViewById(android.R.id.title); if(tv == null) { continue; } v.setBackgroundResource(R.drawable.your_tab_selector_drawable); }