TabHost getTabWidget - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TabHost getTabWidget method.

This code example shows how to use the following methods:getTabWidget, setCurrentTab
            // Unfortunately when TabHost changes the current tab, it kindly 
            // also takes care of putting focus on it when not in touch mode. 
            // The jerk. 
            // This hack tries to prevent this from pulling focus out of our 
            // ViewPager. 
            TabWidget widget = mTabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            mTabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        } 
 
        @Override 
        public void onPageScrollStateChanged(int state) {
        } 
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getTabWidget, setCurrentTab
 
	@Override 
	public void onPageSelected(int position)
	{ 
		// this hack tries to prevent this from pulling focus out of our ViewPager 
		TabWidget widget = mTabHost.getTabWidget();
		int oldFocusability = widget.getDescendantFocusability();
		widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
		mTabHost.setCurrentTab(position);
		widget.setDescendantFocusability(oldFocusability);
	} 
 
	 
	@Override 
	public void onPageScrollStateChanged(int state)
	{ 
 
	} 
 
 
6
CodeRank
This code example shows how to use the following methods:addTab, getTabWidget, newTabSpec, setOnTabChangedListener, setup
            mTabHost.setup();
            mTabHost.setOnTabChangedListener(this);
        } 
         
        // Set the tab properties. 
        TabSpec tabSpec = mTabHost.newTabSpec(tag);
        tabSpec.setIndicator(tab.getText());
        tabSpec.setContent(new DummyTabFactory(mActivity));
         
        // Add the tab to the interface. 
        mTabList.put(tag, tab);
        mTabHost.addTab(tabSpec);
         
        // Shorten the tab's height because there is no icon to display. 
        // The tab would display an empty space instead of the icon otherwise. 
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD || Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
            TabWidget widget = mTabHost.getTabWidget();
            int height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 40, mActivity.getResources().getDisplayMetrics());
            RelativeLayout child = (RelativeLayout)widget.getChildAt(widget.getChildCount() - 1);
            child.getLayoutParams().height = height;

6
CodeRank
This code example shows how to use the following methods:addTab, getTabWidget, newTabSpec
		createHorizontalTab(tabHost);
	} 
 
	private void createHorizontalTab(TabHost tabHost) {
 
		tabHost.addTab(tabHost
				.newTabSpec("tab1")
				.setIndicator(
						createIndicatorView(this, tabHost, icon_tab_1, ""))
						.setContent(new Intent(this, Main.class)));		
		 
		tabHost.addTab(tabHost
				.newTabSpec("tab2")
				.setIndicator(
						createIndicatorView(this, tabHost, icon_tab_2, ""))
						.setContent(new Intent(this, ActivityGroupPaint.class)));
		 
		tabHost.addTab(tabHost
				.newTabSpec("tab3")
				.setIndicator(

6
CodeRank
This code example shows how to use the following methods:getTabWidget, setCurrentTab
            // Unfortunately when TabHost changes the current tab, it kindly 
            // also takes care of putting focus on it when not in touch mode. 
            // The jerk. 
            // This hack tries to prevent this from pulling focus out of our 
            // ViewPager. 
            TabWidget widget = mTabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            mTabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        } 
 
        @Override 
        public void onPageScrollStateChanged(int state) {
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:addTab, getTabWidget, newTabSpec
 
	public static void setMyTabs(TabHost tabHost, Context context){
		 
 
		 
        TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
        TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
 
        firstTabSpec.setIndicator("Bars");
        secondTabSpec.setIndicator("Days");
         
        firstTabSpec.setContent(new Intent(context, BarSpecials.class));
        secondTabSpec.setContent(new Intent(context, DailySpecials.class));
         
        tabHost.addTab(firstTabSpec);
        tabHost.addTab(secondTabSpec);
      
        tabHost.getTabWidget().setCurrentTab(0);
         
	} 

5
CodeRank
This code example shows how to use the following methods:getCurrentTab, getTabWidget
        tabHost.addTab(searchspec); // Adding search tab
        setTabColor(tabHost);
        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener(){
        	  @Override 
        	  public void onTabChanged(String tabId) {
        	    int tab = tabHost.getCurrentTab();
        	    tabHost.getTabWidget().getChildAt(tab).setBackgroundColor(Color.parseColor("#FFFFFF"));
        	    setTabColor(tabHost);
        	  } 
        	}); 
         
         
    } 
     
    public static void setTabColor(TabHost tabhost) {
        for(int i=0;i<tabhost.getTabWidget().getChildCount();i++)
        { 
            tabhost.getTabWidget().getChildAt(i).setBackgroundColor(Color.WHITE); //unselected
        } 
        tabhost.getTabWidget().getChildAt(tabhost.getCurrentTab()).setBackgroundColor(Color.parseColor("#FFFFFF")); // selected
5
CodeRank
This code example shows how to use the following methods:getCurrentTab, getTabWidget, setCurrentTab
	} 
 
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		// TODO Auto-generated method stub 
		int total = tabHost.getTabWidget().getChildCount();
		int current = tabHost.getCurrentTab();
		int index = 0;
		// TODO Auto-generated method stub 
		if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE
				&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
			// Fling left 
			Toast.makeText(this, "向左手势", Toast.LENGTH_SHORT).show();
 
			index = current + 1 > total ? total - 1 : current + 1;
			tabHost.setCurrentTab(index);
		} else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
				&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
			// Fling right 
			index = current - 1 < 0 ? 0 : current - 1;

5
CodeRank
This code example shows how to use the following methods:getTabWidget, setCurrentTab
            // Unfortunately when TabHost changes the current tab, it kindly 
            // also takes care of putting focus on it when not in touch mode. 
            // The jerk. 
            // This hack tries to prevent this from pulling focus out of our 
            // ViewPager. 
            TabWidget widget = mTabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            mTabHost.setCurrentTab(position);
            widget.setDescendantFocusability(oldFocusability);
        } 
 
        @Override 
        public void onPageScrollStateChanged(int state) {
        } 
    } 
} 
4
CodeRank
This code example shows how to use the following methods:getTabWidget, setCurrentTab
            // Unfortunately when TabHost changes the current tab, it kindly 
            // also takes care of putting focus on it when not in touch mode. 
            // The jerk. 
            // This hack tries to prevent this from pulling focus out of our 
            // ViewPager. 
            TabWidget widget = mTabHost.getTabWidget();
            int oldFocusability = widget.getDescendantFocusability();
            widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
            mTabHost.setCurrentTab(i);
            widget.setDescendantFocusability(oldFocusability);
        } 
 
        public void onPageScrollStateChanged(int i) {
        } 
 
        public void onTabChanged(String tabId) {
            int position = mTabHost.getCurrentTab();
            mViewPager.setCurrentItem(position);
        } 
 
4
CodeRank

Related TabHost getTabWidget Questions & Answers:

getTabWidget Method Overview
See Code Examples for other Android TabHost Methods: