日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
安卓開發(fā)底部tab的實(shí)現(xiàn)

1.MainActivity代碼:

滁州網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。成都創(chuàng)新互聯(lián)于2013年開始到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選成都創(chuàng)新互聯(lián)。

(也就是TabsFrame)

package com.example.frametabhost;

import com.example.function.WebGo;
import com.example.licaizhuanjia.MainActivity;
import com.example.licaizhuanjia.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class TabsFrame extends FragmentActivity {

     private FragmentTabHost fragmentTabHost;
     private String texts[] = { "開始", "好友", "群組", "更多" };
     private int p_w_picpathButton[] = { R.drawable.selector1,
             R.drawable.selector2,
             R.drawable.selector3,
             R.drawable.selector4};
     private Class fragmentArray[] = {Page1.class,
             Page2.class,
             Page3.class,
             Page4.class};  

     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabsframe);
    
            // 實(shí)例化tabhost
            fragmentTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
            fragmentTabHost.setup(this, getSupportFragmentManager(),R.id.maincontent);
    
             for (int i = 0; i < texts.length; i++) {
                TabSpec spec=fragmentTabHost.newTabSpec(texts[i]).setIndicator(getView(i));
                fragmentTabHost.addTab(spec, fragmentArray[i], null);
                 
                //設(shè)置背景(必須在addTab之后,由于需要子節(jié)點(diǎn)(底部菜單按鈕)否則會出現(xiàn)空指針異常)
                fragmentTabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.bgselector);
            //背景替換

}
      }
    private View getView(int i) {
         //取得布局實(shí)例
         View view=View.inflate(TabsFrame.this, R.layout.tabcontent, null);
         
         //取得布局對象
         ImageView p_w_picpathView=(ImageView) view.findViewById(R.id.p_w_picpath);
         TextView textView=(TextView) view.findViewById(R.id.text);
         
         //設(shè)置圖標(biāo)
         p_w_picpathView.setImageResource(p_w_picpathButton[i]);
         //設(shè)置標(biāo)題
         textView.setText(texts[i]);
         return view;
    }
    public boolean onKeyDown(int KeyCode,KeyEvent Event){

            if(KeyCode==KeyEvent.KEYCODE_BACK){
               Intent intent=new Intent(TabsFrame.this,MainActivity.class);
           startActivity(intent);
           finish();
            }
        return true;
    }
 
 }
2. 然后是4個(gè)Page,代碼都一樣

public class Page1 extends Fragment{
         @Override
         public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
             return inflater.inflate(R.layout.page1, null);
         }
}

主要代碼就是這些

然后是xml布局文件

3.在tabsframe里

      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical" >
 
     
 
               android:id="@+id/maincontent"
         android:layout_width="fill_parent"
         android:layout_height="0dp"
         android:layout_weight="1" >
   
     
    
 
              android:id="@android:id/tabhost"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:background="@drawable/tab_bg" >
 
                     android:id="@android:id/tabcontent"
             android:layout_width="0dp"
             android:layout_height="0dp"
             android:layout_weight="0" >
        
   
 

4.tabcontent.xml里是底部標(biāo)簽欄的圖標(biāo)

      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:gravity="center_horizontal"
      android:orientation="vertical" >
 
                android:id="@+id/p_w_picpath"
         android:layout_height="wrap_content"
         android:layout_width="wrap_content"
         />
              android:id="@+id/text"
         android:padding="2dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:textColor="@android:color/white"
         />
 

5.在selector1,2,3,4里(寫在drawable文件夾里)



   
   

6.在bgselector.xml里



    
    

7.4個(gè)page的xml(4個(gè)都一樣的代碼)。

      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:background="@drawable/tabframe1"
   >

                android:id="@+id/text"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="22dp"
          android:text="正在開發(fā)中。。。。。"
          android:textSize="20dp" />
 
 

代碼截圖:

安卓開發(fā) 底部tab的實(shí)現(xiàn)

安卓開發(fā) 底部tab的實(shí)現(xiàn)

安卓開發(fā) 底部tab的實(shí)現(xiàn)

安卓開發(fā) 底部tab的實(shí)現(xiàn)

需要源碼就給我留言。

實(shí)現(xiàn)后的界面如下:

安卓開發(fā) 底部tab的實(shí)現(xiàn)

安卓開發(fā) 底部tab的實(shí)現(xiàn)

安卓開發(fā) 底部tab的實(shí)現(xiàn)

安卓開發(fā) 底部tab的實(shí)現(xiàn)


當(dāng)前文章:安卓開發(fā)底部tab的實(shí)現(xiàn)
鏈接URL:http://www.dlmjj.cn/article/pippoj.html