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;
        }
        
    }

     

  • 相关阅读:
    linux部署nuxt.js项目
    vue---el-table设置表头居中,内容列居中/左对齐/右对齐
    偶然看到的jquery选择器性能问题
    关于js中的回调函数问题
    html5图片上传(搬砖)
    css上传文件样式元素样式美化
    小记--转自张鑫旭的css命名规则
    关于nodeJS 在webstorm中的服务器配置
    关于window上的github 上传本地文件--傻瓜式教程
    关于PS的基本操作
  • 原文地址:https://www.cnblogs.com/gongcb/p/2494491.html
Copyright © 2011-2022 走看看