Android TabHost中实现标签的滚动

http://www.cnblogs.com/shirley-1019/archive/2013/04/10/3012824.html

非常漂亮的一段代码:

public class TabhostTestActivity extends TabActivity implements
       TabContentFactory {
   private String[] lables = new String[] { "首页", "消息", "朋友", "更多" };
 private int[] icons = new int[] { R.drawable.ic_home, R.drawable.ic_msg, R.drawable.ic_friend, R.drawable.ic_more };

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.tabhost);
       TabHost th = getTabHost();
       tabHost = getTabHost();
  for (int i = 0; i < lables.length; i++) {
   View view = LayoutInflater.from(this).inflate(R.layout.menu, null);
   ImageView menu_ic = (ImageView) view.findViewById(R.id.menu_ic);
   menu_ic.setImageResource(icons[i]);
   TextView text = (TextView) view.findViewById(R.id.menu_lable);
   text.setText(lables[i]);
   tabHost.addTab(tabHost.newTabSpec(String.valueOf(i)).setIndicator(view).setContent(this));
  }
  tabHost.setCurrentTab(0);   }

 @Override
 public void onTabChanged(String tabId) {
  // tabId 为newTabSpec(String tag) 中传入的字符串tag,这里tag是0,1,2,3 可以转换为整形便于判断
  int tabID = Integer.valueOf(tabId);
  for (int i = 0; i < mTabWidget.getChildCount(); i++) {
   if (i == tabID) {
    mTabWidget.getChildAt(i).setBackgroundResource(
      R.drawable.indicator_selected);
   } else {
    mTabWidget.getChildAt(i).setBackgroundResource(
      R.drawable.indicator_unselected);
   }
  }
 }

 

TabHost通过手势切换Activity

http://www.eoeandroid.com/thread-238527-1-1.html  简直帅爆了

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。