zoukankan      html  css  js  c++  java
  • Android开发学习之TabView选项卡具体解释 -- 基于Android4.4

    版权声明:本文为博主原创文章,未经博主同意不得转载。

    https://blog.csdn.net/he90227/article/details/24474197

    直接上代码 -- 基于Android4.4


    package com.example.viewdemo1;
    
    import android.app.Activity;
    import android.graphics.Color;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.widget.TabHost;
    
    //新版本号中TabActivity过时了,使用一下的方式
    public class Tab1Activity extends  Activity{
    
    	private TabHost myTabHost;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_tab1); 
    		myTabHost = (TabHost) findViewById(android.R.id.tabhost);
    		myTabHost.setup();//实例化了tabWidget和tabContent  
    		myTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
    		
    		myTabHost.addTab(myTabHost.newTabSpec("腾讯").setIndicator("腾讯",getResources().getDrawable(R.drawable.qq)).setContent(R.id.tab1));
    		myTabHost.addTab(myTabHost.newTabSpec("华为").setIndicator("华为",getResources().getDrawable(R.drawable.huawei)).setContent(R.id.tab2));
    		myTabHost.addTab(myTabHost.newTabSpec("百度").setIndicator("百度",getResources().getDrawable(R.drawable.baidu)).setContent(R.id.tab3));
    	}
    
    /*
    //Android4之前的方式。4之后TabActivity已经过期了
    public class Tab1Activity extends android.app.TabActivity{
    
    	private TabHost myTabHost;
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		myTabHost = this.getTabHost();
    		  
    		LayoutInflater.from(this).inflate(R.layout.activity_tab1, myTabHost.getTabContentView(),true);
    		myTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
    		
    		myTabHost.addTab(myTabHost.newTabSpec("腾讯").setIndicator("腾讯",getResources().getDrawable(R.drawable.qq)).setContent(R.id.tab1));
    		myTabHost.addTab(myTabHost.newTabSpec("华为").setIndicator("华为",getResources().getDrawable(R.drawable.huawei)).setContent(R.id.tab2));
    		myTabHost.addTab(myTabHost.newTabSpec("百度").setIndicator("百度",getResources().getDrawable(R.drawable.baidu)).setContent(R.id.tab3));
    	}*/
        
    		
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		// TODO Auto-generated method stub
    		return super.onCreateOptionsMenu(menu);
    	}
    
    	@Override
    	public boolean onOptionsItemSelected(MenuItem item) {
    		// TODO Auto-generated method stub
    		return super.onOptionsItemSelected(item);
    	}
    	
    }
    


    布局文件


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
    
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </TabWidget>
    
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
    
                    <LinearLayout
                        android:id="@+id/tab1"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
    
                        <Button
                            android:id="@+id/button1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="第一个Tab选项卡" />
    
                    </LinearLayout>
    
                    <LinearLayout
                        android:id="@+id/tab2"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                        <Button
                            android:id="@+id/button2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="第二个Tab选项卡" />
                    </LinearLayout>
    
                    <LinearLayout
                        android:id="@+id/tab3"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >
                        <Button
                            android:id="@+id/button3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="第三个Tab选项卡" />
                    </LinearLayout>
                </FrameLayout>
            </LinearLayout>
        </TabHost>
    
    </LinearLayout>
    


  • 相关阅读:
    Anaconda-navigator 打不开的解决方法(亲测有效!)
    Python3.7安装keras和TensorFlow的教程图解
    win10环境下使用anaconda安装opencv
    windows环境下的Anaconda安装与OpenCV机器视觉环境搭建
    各种工具汇总(20210702更新)
    关于文章致谢
    公共数据库信息汇总(20210709更新)
    关于摆脱痛苦
    pip 本地安装 python 包
    报错Error: Sorted input specified, but the file file.bedgraph has the following out of order record解决方案
  • 原文地址:https://www.cnblogs.com/mqxnongmin/p/10654650.html
Copyright © 2011-2022 走看看