• 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>

  • 相关阅读:
    1)①爬取中国新闻网科技相关部分新闻
    摘记
    KNN算法[分类算法]
    Naive Bayes(朴素贝叶斯算法)[分类算法]
    Oracle 隔离级别
    解决问题没必要过于纠结于原理
    Oracle DBMS_METADATA.GET_DDL
    【听海日志】之ORACLE物化视图 [转]http://www.itpub.net/thread-1614812-1-1.html
    oracle 12c 基础
    Postgres查看数据库中的表及表中字段和类型
  • 原文地址:https://www.cnblogs.com/xingmeng/p/2428688.html
Copyright © 2020-2023  润新知