zoukankan      html  css  js  c++  java
  • Android自定义Tabs文字,背景

    public class HomeActivity extends TabActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature ( Window.FEATURE_NO_TITLE );     //去除Title
            setContentView(R.layout.activity_home);
            final TabHost dh =getTabHost(); //获得TabHost实例
            final TabWidget tabWidget = dh.getTabWidget();//获得TabWidget实例
            dh.addTab(dh.newTabSpec("A").setIndicator(getResources().getString(R.string.tab1)).setContent(new Intent(this,FirstActivity.class)));
            dh.addTab(dh.newTabSpec("B").setIndicator(getResources().getString(R.string.tab2)).setContent(new Intent(this,SecondActivity.class)));
            for (int i =0; i < tabWidget.getChildCount(); i++) {
              View child = tabWidget.getChildAt(i);
              final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
              tv.setTextColor(this.getResources().getColorStateList(android.R.color.white));
              tv.setTextSize(10);
              RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams();
              params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //取消文字底边对齐
              params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //设置文字居中对齐
              child.getLayoutParams().height = 30;  
              
                  if(dh.getCurrentTab()==i){
                          child.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_selected));
                  }
                  else {
                          child.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_unselected));
                  }
             }  
    //设置点击切换背景图        
    dh.setOnTabChangedListener(new OnTabChangeListener(){
                    public void onTabChanged(String tabId) {
                     // TODO Auto-generated method stub
                     for (int i =0; i < tabWidget.getChildCount(); i++) {
                      View vvv = tabWidget.getChildAt(i);
                      if(dh.getCurrentTab()==i){
                              vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_selected));
                      }
                      else {
                              vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_unselected));
                      }
                     }
                    }});
        }
  • 相关阅读:
    DEDECMS里面DEDE函数解析
    dede数据库类使用方法 $dsql
    DEDE数据库语句 DEDESQL命令批量替换 SQL执行语句
    织梦DedeCms网站更换域名后文章图片路径批量修改
    DSP using MATLAB 示例 Example3.12
    DSP using MATLAB 示例 Example3.11
    DSP using MATLAB 示例 Example3.10
    DSP using MATLAB 示例Example3.9
    DSP using MATLAB 示例Example3.8
    DSP using MATLAB 示例Example3.7
  • 原文地址:https://www.cnblogs.com/seantown/p/2810034.html
Copyright © 2011-2022 走看看