• tabhost笔记


    不推荐使用

        TabHost mTabHost;
        View mTabHomeView, mTabBookView, mTabSpaceView, mTabMeView;
        ImageView mTabImage;
        TextView mTabTitle;
        Intent mIntent;
        public void initTab(Bundle savedInstanceState) {
            // 获取TabHost对象
            mTabHost = (TabHost) findViewById(R.id.tabhost);
            // 如果没有继承TabActivity时,通过该种方法加载启动tabHost
            //mTabHost.setup();
            LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
            mLocalActivityManager.dispatchCreate(savedInstanceState);
            mTabHost.setup(mLocalActivityManager);
    
    
    
            mTabHomeView = LayoutInflater.from(this).inflate(R.layout.tab_cell_home, null);
            mTabBookView = LayoutInflater.from(this).inflate(R.layout.tab_cell_book, null);
            mTabSpaceView = LayoutInflater.from(this).inflate(R.layout.tab_cell_space, null);
            mTabMeView = LayoutInflater.from(this).inflate(R.layout.tab_cell_me, null);
    
            this.addTab(mTabHomeView, mRes.getDrawable(R.drawable.tab_bg), R.string.tab_title_home);
            this.addTab(mTabBookView, mRes.getDrawable(R.drawable.tab_bg), R.string.tab_title_book);
            this.addTab(mTabSpaceView, mRes.getDrawable(R.drawable.tab_bg), R.string.tab_title_space);
            this.addTab(mTabMeView, mRes.getDrawable(R.drawable.tab_bg), R.string.tab_title_me);
    
            mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
                @Override
                public void onTabChanged(String s) {
                    mActionTitle.setText(s);
                }
            });
            mTabHost.setCurrentTab(0);
            mActionTitle.setText(mRes.getString(R.string.tab_title_home));
        }
    
        public void addTab(View tabview, Drawable picture, int stringId) {
            String title = mRes.getString(stringId);
            switch (stringId) {
                case R.string.tab_title_home:
                    mIntent = new Intent(this, HomeActivity.class);
                    break;
                case R.string.tab_title_book:
                    mIntent = new Intent(this, BookActivity.class);
                    break;
                case R.string.tab_title_space:
                    mIntent = new Intent(this, SpaceActivity.class);
                    break;
                case R.string.tab_title_me:
                    mIntent = new Intent(this, MeActivity.class);
                    break;
                default:
                    break;
            }
            mTabImage  = (ImageView)tabview.findViewById(R.id.tab_picture);
            mTabTitle = (TextView)tabview.findViewById(R.id.tab_title);
            mTabImage.setImageDrawable(picture);
            mTabTitle.setText(title);
    
            mTabHost.addTab(mTabHost.newTabSpec(title)
                    .setIndicator(tabview)
                    .setContent(mIntent));
        }
  • 相关阅读:
    How to Compile Java DBus
    BZOJ 2783 JLOI 2012 树 乘+二分法
    Robotium原则的实施源代码分析
    基本的负载均衡算法
    人大、上财、复旦、上交四校2013年应届金融硕士就业去向
    2014届上财金融硕士就业情况
    三跨),总分420+
    复旦金融专硕和上财金融专硕
    一个三跨考生三战上海财经大学金融硕士的考研经验
    董某某
  • 原文地址:https://www.cnblogs.com/wjhblogs/p/4900858.html
Copyright © 2020-2023  润新知