• tabhost标签


    主程序

    InitActivity.java

    package com.delightPress.chap61;

    import com.delightPress.chap61.tabActivity.Income;
    import com.delightPress.chap61.tabActivity.Outcome;
    import com.delightPress.chap61.tabActivity.Totalcome;

    import android.app.Activity;
    import android.app.TabActivity;
    import android.content.Intent;
    import android.content.res.Resources;
    import android.os.Bundle;
    import android.widget.TabHost;

    import com.delightPress.chap61.R;

    public class InitActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); //object to get Drwable
    TabHost tabHost = getTabHost(); //The activity TabHost
    TabHost.TabSpec spec; //TabSpec for each tab
    Intent intent; //Intent for each tab

    //Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, Income.class);

    //初始化每一个标签的TabSpec,并且将它加入tabHost
    spec = tabHost.newTabSpec("Income").setIndicator("Income",res.getDrawable(R.drawable.tab_icon1)).setContent(intent);
    tabHost.addTab(spec);

    //Do the same for the other tabs
    intent = new Intent().setClass(this, Outcome.class);
    spec = tabHost.newTabSpec("Outcome").setIndicator("Outcome",res.getDrawable(R.drawable.tab_icon1)).setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, Totalcome.class);
    spec = tabHost.newTabSpec("Total").setIndicator("Total",res.getDrawable(R.drawable.tab_icon1)).setContent(intent);
    tabHost.addTab(spec);

    //调用默认的标签
    tabHost.setCurrentTab(2);
    }
    }

    请求的对应的class都是加载标签中的图片和文字

    main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
    <TabWidget
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    </TabWidget>
    <FrameLayout
    android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
    </FrameLayout>
    </LinearLayout>

    </TabHost>

    图片组合:

    drawable文件夹下

    tab_icon1.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <!-- 被选择时用高亮度的灰色 -->
    <item android:drawable="@drawable/google_grey"
    android:state_selected="true"></item>
    <!-- 平时用透明底的白色 -->
    <item android:drawable="@drawable/google_white" />

    </selector>

  • 相关阅读:
    PLSQL配置介绍
    jquery实现无外边框table
    以太坊白皮书
    区块链技术教程,如何从零开始学习以太坊及区块链
    Python机器学习中文版
    史上最全TensorFlow学习资源汇总
    什么是人工智能?终于说明白了
    Python 语音识别
    Step by Step 真正从零开始,TensorFlow详细安装入门图文教程!帮你完成那个最难的从0到1
    什么是加密经济学? 初学者终极指南
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2428688.html
Copyright © 2020-2023  润新知