乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      自定義Tab選項卡 - Android SDK/應(yīng)用技術(shù)討論 - 有米廣告-最精準的手機廣告平臺-幫助國內(nèi)開發(fā)者盈利 - Powered by Discuz!

       shaobin0604@163.com 2010-05-25
      這個需求估計大家都是需要,這幾天剛好做了一個項目,也大概的研究了一下,下面將自己的研究成果展現(xiàn)給大家,希望對大家有用!

      我就直接貼核心部分的源碼了,其他東西大家自己添加,不要懶到只跟我要全部源碼,大家自己做一遍才能真正學(xué)到東西!

      先貼效果給大家看看:

      device11.png device22.png device33.png


      1. import android.app.TabActivity;
      2. import android.content.Intent;
      3. import android.os.Bundle;
      4. import android.widget.*;
      5. import android.widget.TabHost.OnTabChangeListener;
      6. import android.os.Build;
      7. import android.view.View;
      8. import java.lang.reflect.Field;
      9. import android.view.LayoutInflater;

      10. public class testTabActivity extends TabActivity {
      11.   /** Called when the activity is first created. */
      12.      @Override
      13.      public void onCreate(Bundle savedInstanceState) {
      14.          super.onCreate(savedInstanceState);
      15.          
      16.          int width =45;
      17.          int height =48;
      18.          
      19.          final TabHost tabs = getTabHost();
      20.          final TabWidget tabWidget = tabs.getTabWidget();
      21.          
      22.          Field mBottomLeftStrip;
      23.          Field mBottomRightStrip;
      24.       
      25.          LayoutInflater.from(this).inflate(R.layout.tab_views, tabs.getTabContentView(), true);
      26.       
      27.          tabs.addTab(tabs.newTabSpec("first tab")
      28.               .setIndicator("信息",getResources().getDrawable(R.drawable.m))
      29.               .setContent(new Intent(testTabActivity.this,OneActivty.class))
      30.               );
      31.          
      32.          tabs.addTab(tabs.newTabSpec("second tab")
      33.           .setIndicator("收藏",getResources().getDrawable(R.drawable.n))
      34.           .setContent(R.id.content));
      35.          
      36.          tabs.addTab(tabs.newTabSpec("second tab")
      37.               .setIndicator("設(shè)置",getResources().getDrawable(R.drawable.s))
      38.               .setContent(R.id.content));
      39.          


      40.          for (int i =0; i < tabWidget.getChildCount(); i++) {
      41.              /**
      42.               * 設(shè)置高度、寬度,不過寬度由于設(shè)置為fill_parent,在此對它沒效果
      43.               */
      44.              tabWidget.getChildAt(i).getLayoutParams().height = height;
      45.              tabWidget.getChildAt(i).getLayoutParams().width = width;
      46.             
      47.          
      48.           /**
      49.            * 設(shè)置tab中標題文字的顏色,不然默認為黑色
      50.            */
      51.            final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
      52.          
      53.            tv.setTextColor(this.getResources().getColorStateList(android.R.color.white));
      54.          
      55.             
      56.          
      57.             
      58.              /**
      59.               * 此方法是為了去掉系統(tǒng)默認的色白的底角
      60.               *
      61.               * 在 TabWidget中mBottomLeftStrip、mBottomRightStrip
      62.               * 都是私有變量,但是我們可以通過反射來獲取
      63.               *
      64.               * 由于還不知道Android 2.2的接口是怎么樣的,現(xiàn)在先加個判斷好一些
      65.               */
      66.           if (Float.valueOf(Build.VERSION.RELEASE) <= 2.1) {
      67.                 try {
      68.                    mBottomLeftStrip = tabWidget.getClass().getDeclaredField ("mBottomLeftStrip");
      69.                    mBottomRightStrip = tabWidget.getClass().getDeclaredField ("mBottomRightStrip");
      70.                    if(!mBottomLeftStrip.isAccessible()) {
      71.                      mBottomLeftStrip.setAccessible(true);
      72.                    }
      73.                    if(!mBottomRightStrip.isAccessible()){
      74.                      mBottomRightStrip.setAccessible(true);
      75.                    }
      76.                   mBottomLeftStrip.set(tabWidget, getResources().getDrawable (R.drawable.no));
      77.                   mBottomRightStrip.set(tabWidget, getResources().getDrawable (R.drawable.no));
      78.                   
      79.                 } catch (Exception e) {
      80.                   e.printStackTrace();
      81.                 }
      82.           } else {
      83.           /**
      84.           * 不做任何處理
      85.           */
      86.           }
      87.          View vvv = tabWidget.getChildAt(i);
      88.    if(tabs.getCurrentTab()==i){
      89.            vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_button));
      90.    }
      91.    else {
      92.            vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.bar));
      93.    }
      94.          
      95.          }
      96.          /**
      97.           * 當點擊tab選項卡的時候,更改當前的背景
      98.           */
      99.          tabs.setOnTabChangedListener(new OnTabChangeListener(){
      100.     @Override
      101.     public void onTabChanged(String tabId) {
      102.      // TODO Auto-generated method stub
      103.      for (int i =0; i < tabWidget.getChildCount(); i++) {
      104.       View vvv = tabWidget.getChildAt(i);
      105.       if(tabs.getCurrentTab()==i){
      106.               vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_button));
      107.       }
      108.       else {
      109.               vvv.setBackgroundDrawable(getResources().getDrawable(R.drawable.bar));
      110.       }
      111.      }
      112.     }});
      113.          
      114.      }
      115.      
      116.      
      117. }
      復(fù)制代碼

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多