一、效果

2、主要代码

 

 

 (1).activity_main.xml

<?xml version="1.0" encoding="utf-8"?>                                                                                                                                                    

(2)styles.xml

                40dp

(3)strings.xml

    ToolBar    首页    分类    购物车

(4)MainActivity.java

package com.example.toolbar;import android.app.TabActivity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.LinearLayout;import android.widget.TabHost;public class MainActivity extends TabActivity implements View.OnClickListener{    private static final String TAG = "MainActivity";    private Bundle mBundle = new Bundle();    private TabHost tab_host;    private LinearLayout ll_first, ll_second, ll_third;    private String FIRST_TAG = "first";    private String SECOND_TAG = "second";    private String THIRD_TAG = "third";    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        mBundle.putString("tag", TAG);        ll_first = findViewById(R.id.ll_first);        ll_second = findViewById(R.id.ll_second);        ll_third = findViewById(R.id.ll_third);        ll_first.setOnClickListener(this);        ll_second.setOnClickListener(this);        ll_third.setOnClickListener(this);        tab_host = getTabHost();        tab_host.addTab(getNewTab(FIRST_TAG, R.string.menu_first, R.drawable.ic_launcher_background, Main2Activity.class));        tab_host.addTab(getNewTab(SECOND_TAG, R.string.menu_second, R.drawable.ic_launcher_background, Main3Activity.class));        tab_host.addTab(getNewTab(THIRD_TAG, R.string.menu_third, R.drawable.ic_launcher_background, Main4Activity.class));        changeContainerView(ll_first);    }    private TabHost.TabSpec getNewTab(String spec, int label, int icon, Class<?>cls) {        Intent intent = new Intent(this, cls).putExtras(mBundle);        return tab_host.newTabSpec(spec).setContent(intent).setIndicator(getString(label), getResources().getDrawable(icon));    }    @Override    public void onClick(View view) {        switch (view.getId()) {            case R.id.ll_first:            case R.id.ll_second:            case R.id.ll_third:                changeContainerView(view);        }    }    private void changeContainerView(View v) {        ll_first.setSelected(false);        ll_second.setSelected(false);        ll_third.setSelected(false);        v.setSelected(true);        if (v == ll_first) {            tab_host.setCurrentTabByTag(FIRST_TAG);        } else if (v == ll_second) {            tab_host.setCurrentTabByTag(SECOND_TAG);        } else if (v == ll_third) {            tab_host.setCurrentTabByTag(THIRD_TAG);        }    }}

3、资源链接

如果还不清楚,https://download.csdn.net/download/chicaidecaiji/12409083给上完整实例

更多相关文章

  1. android 按钮置灰效果
  2. Android四大组件Service之bindService启动
  3. 三步实现Android悬浮效果
  4. Android中实现整个视图切换的左右滑动效果
  5. Android的Task和Activity相关
  6. Android第三十一期 - 市面上所有引导页的效果
  7. Android(安卓)Textview控件
  8. Android的GridView控件点击图片变暗效果
  9. Android(安卓)动画效果 --Animation 动画(讲解了所有的Android动

随机推荐

  1. android技术篇(二)解锁System分区
  2. android开发学习如何一体化?从入门到高端
  3. 使用java来做Kinect开发
  4. Nokia 为何只做 Windows Phone :我怕 Andr
  5. 详解Android首选项框架的使用实例
  6. 开发者应如何看待iOS平台和Android平台
  7. kxte9应用局限
  8. cocos2d-x 2.0.1版本的使用 在android 上
  9. 在PC虚拟机中安装apk软件
  10. android用户输入系统详细说明