<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Android FragmentTabHost底部選項(xiàng)卡實(shí)現(xiàn)

      記錄一下底部選項(xiàng)卡的實(shí)現(xiàn),很常見的代碼,大神勿嘲笑。

      說(shuō)一下思路,在activity底部要放上FragmentTabHost放上選項(xiàng),幾個(gè)無(wú)所謂,每個(gè)選項(xiàng)卡都對(duì)應(yīng)一個(gè)fragment,點(diǎn)擊選項(xiàng)卡顏色改變可以用selector(選擇器)來(lái)實(shí)現(xiàn),焦點(diǎn)選中的時(shí)候一個(gè)顏色,失去焦點(diǎn)的時(shí)候,另一個(gè)顏色。

      首先,activity布局

      <?xml version="1.0" encoding="utf-8"?>
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context="com.example.sdtz.wenmingweifang.MainActivity">
          <FrameLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:id="@+id/fl">
      
          </FrameLayout>
          <LinearLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:background="#ffffff"
              android:gravity="center"
              android:orientation="vertical">
              <android.support.v4.app.FragmentTabHost
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/fl"
                  android:id="@+id/tabHost">
      
              </android.support.v4.app.FragmentTabHost>
          </LinearLayout>
      </RelativeLayout>



      acitivity中主要代碼的代碼,其中view1,view2.....就是選項(xiàng)卡的內(nèi)容,一般就是一張圖片,下面一段文字(首頁(yè)啥的),標(biāo)紅的部分,就是每個(gè)界面的fragment,可以在各個(gè)fragment中寫每個(gè)界面的代碼

       tabHost = (FragmentTabHost) findViewById(R.id.tabHost);
              view = LayoutInflater.from(getBaseContext()).inflate(R.layout.pop_window1,null);
              view1 = LayoutInflater.from(getBaseContext()).inflate(R.layout.shouye_view,null);
              view2 = LayoutInflater.from(getBaseContext()).inflate(R.layout.shouye_2_view,null);
              view3 = LayoutInflater.from(getBaseContext()).inflate(R.layout.shouye_3,null);
              view4 = LayoutInflater.from(getBaseContext()).inflate(R.layout.shouye_4,null);
              view5 = LayoutInflater.from(getBaseContext()).inflate(R.layout.shouye_5,null);
              try{
                  tabHost.setup(this,getSupportFragmentManager(),R.id.fl);
                  Fragment mainFragment = new MianFragment();
                  TabHost.TabSpec tabSpec0 =
                          tabHost.newTabSpec(str[0]).setIndicator(view1);
                  tabHost.addTab(tabSpec0,mainFragment.getClass(),null);
      
                  Fragment SecondFragment = new SencondFragment();
                  TabHost.TabSpec tabSpec2 =
                          tabHost.newTabSpec(str[1]).setIndicator(view2);
                  tabHost.addTab(tabSpec2,SecondFragment.getClass(),null);
      
                  Fragment ShezhiFragmet = new ShezhiFragment();
                  TabHost.TabSpec tabSpec1 =
                          tabHost.newTabSpec(str[2]).setIndicator(view3);
                  tabHost.addTab(tabSpec1,ShezhiFragmet.getClass(),null);
      
                  Fragment MoreFragment = new MoreFragment();
                  TabHost.TabSpec tabSpec4 =
                          tabHost.newTabSpec(str[3]).setIndicator(view4);
                  tabHost.addTab(tabSpec4,MoreFragment.getClass(),null);
      
      
                  Fragment MeFragment = new MeFragment();
      
                  TabHost.TabSpec tabSpec5 =
                          tabHost.newTabSpec(str[4]).setIndicator(view5);
                  tabHost.addTab(tabSpec5,MeFragment.getClass(),null);
              }catch (Exception e){
                  e.printStackTrace();
              }

      下面是選項(xiàng)卡的xml,標(biāo)志的部分就是 選擇器,標(biāo)記的部分就是選擇器,用來(lái)選項(xiàng)卡的顏色變化

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical" android:layout_width="match_parent"
          android:layout_height="match_parent">
          <ImageView
              android:layout_marginTop="@dimen/y10"
              android:layout_width="match_parent"
              android:layout_height="20dp"
              android:src="@drawable/shouye_view_select"
              android:id="@+id/img"/>
          <TextView
              android:layout_marginBottom="@dimen/y10"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:gravity="center"
              android:textColor="@drawable/shouye_1_text"
              android:textSize="12sp"
              android:text="首頁(yè)"/>
      </LinearLayout>

      選擇器代碼:

      就是有兩張不同顏色的圖片,焦點(diǎn)選中和不選中切換不同的圖片,android:state_selected="true",就是焦點(diǎn)選中,

      文字的選擇器也是一樣,切換不同的顏色

      <?xml version="1.0" encoding="utf-8"?>
      <selector xmlns:android="http://schemas.android.com/apk/res/android">
          <item
              android:state_selected="true"
              android:drawable="@drawable/home_on">
          </item>
      
          <item android:drawable="@drawable/home">
      
          </item>
      </selector>

      <?xml version="1.0" encoding="utf-8"?>
      <selector xmlns:android="http://schemas.android.com/apk/res/android">
          <item
              android:state_selected="true"
              android:color="#fd0101">
          </item>
      
          <item  android:color="#000000">
      
          </item>
      </selector>

      至此,選項(xiàng)卡的代碼已經(jīng)基本完成,調(diào)試一下就可以運(yùn)行了

      posted @ 2018-01-19 09:53  頭一回  閱讀(785)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 宅男噜噜噜66在线观看| 久久国产精品老人性| 日本熟妇XXXX潮喷视频| 国产午夜福利精品片久久| 黑人巨大无码中文字幕无码| 国产色悠悠在线免费观看| 天堂V亚洲国产V第一次| 日本怡春院一区二区三区| 亚洲av乱码久久亚洲精品| 精品无码一区二区三区爱欲| 国产成人精品亚洲午夜| 国内精品大秀视频日韩精品| 欧美性xxxxx极品| 国产免费播放一区二区三区| 深夜av在线免费观看| 欧美成人黄在线观看| 亚洲一区黄色| 亚洲精品亚洲人成人网| 高清中文字幕国产精品| 长泰县| 人人人澡人人肉久久精品| 99在线精品免费视频九九视| 无码熟妇人妻av影音先锋| 国产黄色一区二区三区四区| 丝袜国产一区av在线观看| 亚洲国产成人无码av在线播放 | 极品尤物被啪到呻吟喷水| 亚洲第一视频区| 精品亚洲欧美高清不卡高清 | 一区二区三区四区精品黄| 性夜夜春夜夜爽夜夜免费视频| 亚洲精品一区二区制服| 精品久久久久久国产| 国产av日韩精品一区二区| 国产色悠悠综合在线观看| 国产精欧美一区二区三区| 国产日韩入口一区二区| 滕州市| 色偷偷亚洲女人天堂观看| 国产suv精品一区二区四| 中文字幕熟妇人妻在线视频|