首页 新闻 赞助 找找看

android TabHost(标题不知道怎么写。。。。。。)

0
悬赏园豆:10 [已解决问题] 解决于 2017-10-03 16:15
复制代码
package com.lyf.ai.myapplication;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TabHost;

public class MainActivity extends TabActivity implements OnCheckedChangeListener{

    /*
        声明全局变量
    */
    private TabHost mTabHost;
    private Intent mAIntent;
    private Intent mBIntent;
    private Intent mCIntent;
    private Intent mDIntent;
    private Intent mEIntent;

    /*
        在第一次创建活动时调用。
    */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //标记为“无标题”功能,在屏幕顶部关闭标题。
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.maintabs);
        //初始化各个tab标签对应的intent
        this.mAIntent = new Intent(this,BiddingInformationActivity.class);
        this.mBIntent = new Intent(this,BActivity.class);
        this.mCIntent = new Intent(this,CActivity.class);
        this.mDIntent = new Intent(this,DActivity.class);
        this.mEIntent = new Intent(this,MoreActivity.class);
        //为RadioGroup设置监听
        ((RadioButton) findViewById(R.id.radio_button0)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button1)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button2)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button3)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radio_button4)).setOnCheckedChangeListener(this);

        setupIntent();
    }

    /*
        点击触发事件,
    */
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked){
            switch (buttonView.getId()) {
                case R.id.radio_button0:
                    this.mTabHost.setCurrentTabByTag("A_TAB");
                    break;
                case R.id.radio_button1:
                    this.mTabHost.setCurrentTabByTag("B_TAB");
                    break;
                case R.id.radio_button2:
                    this.mTabHost.setCurrentTabByTag("C_TAB");
                    break;
                case R.id.radio_button3:
                    this.mTabHost.setCurrentTabByTag("D_TAB");
                    break;
                case R.id.radio_button4:
                    this.mTabHost.setCurrentTabByTag("MORE_TAB");
                    break;
            }
        }

    }

    /*
         为tabHost添加各个标签项
    */
    private void setupIntent() {
        this.mTabHost = getTabHost();
        TabHost localTabHost = this.mTabHost;

        localTabHost.addTab(buildTabSpec("A_TAB", R.string.main_home, R.mipmap.icon_1_n, this.mAIntent));

        localTabHost.addTab(buildTabSpec("B_TAB", R.string.main_news, R.mipmap.icon_2_n, this.mBIntent));

        localTabHost.addTab(buildTabSpec("C_TAB", R.string.main_manage_date, R.mipmap.icon_3_n, this.mCIntent));

        localTabHost.addTab(buildTabSpec("D_TAB", R.string.main_friends, R.mipmap.icon_4_n, this.mDIntent));

        localTabHost.addTab(buildTabSpec("MORE_TAB", R.string.more, R.mipmap.icon_5_n, this.mEIntent));

    }

    /*
        自定义创建标签项的方法
         @param tag 标签标识
         @param resLabel 标签文字
         @param resIcon 标签图片
    */
    private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon, final Intent content) {
        return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel),
                getResources().getDrawable(resIcon)).setContent(content);
    }
}
复制代码

本人新手一 枚,代码看不懂,请求大神解释,或者给参考资料,谢谢大家的帮助!
主要问题有
(1)它是怎么默认开始页面的
(2)如果要跳转一个页面,我又应该怎么写 ,跳转页面后下面的导航栏还要存在

Mr-LYF的主页 Mr-LYF | 菜鸟二级 | 园豆:201
提问于:2017-09-30 20:12
< >
分享
最佳答案
0

问题1:根据你初始化tab标签对应的intent的时候放的Activity第一个就是初始页面了;

问题2:正在努力研发中。。。。耐心等待。

收获园豆:10
MISS_CM丶 | 菜鸟二级 |园豆:228 | 2017-10-01 15:22
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册