zoukankan      html  css  js  c++  java
  • Android:TabHost导航栏

    通常情况下,我们都需要用到TabHost做一个导航功能。

    这也就需要我们更好的使用TabHost进行各项界面之间的跳转。

    首要我们新建一个XML:

    <TabHost 
        android:id="@android:id/tabhost" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/first_bg"
        xmlns:android="http://schemas.android.com/apk/res/android">
        
        <LinearLayout 
            android:orientation="vertical"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">
    
            <FrameLayout 
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent" 
                android:layout_height="0.0dip"
                android:layout_weight="2.0" />
                
            <TabWidget 
                android:id="@android:id/tabs" 
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:padding="2dip"
                android:background="@drawable/down_bar"
                android:layout_weight="0.0"/>
                
        </LinearLayout>
        
    </TabHost>

    MainActivity 我们进行如下操作:

    public class MainActivity extends TabActivity{
        private TabHost mTabHost;
        private LayoutInflater mLayoutInflater;
        
        private Class mTabClassArray[] = {
            ClassicMoiveActivity.class,
            HotMovieActivity.class,
            ExpectMovieActivity.class
        };
        
        private int mImageViewArray[] = {
            R.drawable.sutra,
            R.drawable.hot,
            R.drawable.expect
        };
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            initWidget();
        }
        
        
        private void initWidget() {
            mTabHost = getTabHost();
            mLayoutInflater = LayoutInflater.from(this);
    
            for (int i = 0; i < mTabClassArray.length; i++) {
                TabSpec tabSpec = mTabHost.newTabSpec("").setIndicator(getTabItemView(i)).setContent(getTabItemIntent(i));
                mTabHost.addTab(tabSpec);
                mTabHost.getTabWidget().getChildAt(i)
                        .setBackgroundResource(R.drawable.selector_tab_background);
            }
    
        }
    
        private View getTabItemView(int index) {
            View view = mLayoutInflater.inflate(R.layout.tab_item_view, null);
            
            ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
            if (imageView != null) {
                imageView.setImageResource(mImageViewArray[index]);
            }
            return view;
        }
    
        private Intent getTabItemIntent(int index) {
            Intent intent = new Intent(this, mTabClassArray[index]);
            return intent;
        }
        
    }

     

  • 相关阅读:
    mac 使用指南
    客服系统引用方案
    CSS中margin和padding的区别
    NuGet学习笔记(1)——初识NuGet及快速安装使用
    百度搜索这些词:(百度搜索特效,好玩)
    sql语言:如何查询字符串某个字符的个数?
    Sql日期时间格式转换
    SQL获取当前时间(日期)
    Redis快速入门:初识Redis
    选择Key-Value Store
  • 原文地址:https://www.cnblogs.com/gongcb/p/2494491.html
Copyright © 2011-2022 走看看