分页标签的实现,包括切换事件的监听、tab 的 颜色 背景 字体 的改变、全屏的设置。

.java代码:

package com.example.change;import android.R.color;import android.app.Activity;import android.app.TabActivity;import android.graphics.Color;import android.graphics.Typeface;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.widget.TabHost;import android.widget.TabHost.OnTabChangeListener;import android.widget.TextView;public class MainActivity extends TabActivity {    private TabHost tabHost;    private void addTab() { tabHost.addTab(tabHost  .newTabSpec("tab1")  .setIndicator("TAB1",   getResources().getDrawable(R.drawable.face))  .setContent(R.id.textview1)); tabHost.addTab(tabHost  .newTabSpec("tab2")  .setIndicator("TAB2")  .setContent(R.id.textview2)); tabHost.addTab(tabHost  .newTabSpec("tab3")  .setIndicator("TAB3",   getResources().getDrawable(R.drawable.ic_launcher))  .setContent(R.id.textview3));   }    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        tabHost = getTabHost();        addTab();        tabHost.setCurrentTab(0);        tabHost.setOnTabChangedListener(new OnTabChangeListener(){        public void onTabChanged(String tabId){        updateTab(tabHost);        }        });        //updateTab(tabHost);    }        private void updateTab(final TabHost tabHost) {         for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {             View view = tabHost.getTabWidget().getChildAt(i);             TextView tv = (TextView) tabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title);             tv.setTextSize(16);             tv.setTypeface(Typeface.SERIF, 2);            if (tabHost.getCurrentTab() == i) {            view.setBackgroundColor(Color.BLUE);            tv.setTextColor(Color.WHITE);            }            else {                 view.setBackgroundDrawable(getResources().getDrawable(R.drawable.face2));                tv.setTextColor(Color.BLACK);             }         }     }     }

manifest 代码:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.change"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="21" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name=".MainActivity"            android:label="@string/app_name"             android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>

xml代码:

<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:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical">        <TabWidget            android:id="@android:id/tabs"            android:layout_width="fill_parent"            android:layout_height="wrap_content"/>        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"    android:layout_height="fill_parent">                    <TextView          android:id="@+id/textview1"          android:layout_width="fill_parent"          android:layout_height="fill_parent"          android:text="Linux"          android:textColor="#FF0000"/>      <TextView        android:id="@+id/textview2"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:text="MAC"        android:textColor="#385E0F" />      <TextViewandroid:id="@+id/textview3"android:layout_width="fill_parent"android:layout_height="fill_parent"android:text="Windows"android:textColor="#1E90FF" />        </FrameLayout>    </LinearLayout></TabHost>


更多相关文章

  1. Android(安卓)自定义AlertDialog 去黑边终极解决方案(亲测有效!)
  2. android java js 回调 真心好用
  3. android 获取手机图片裁剪后分享 2
  4. Android触摸事件小小画板(7)
  5. android 动态设置margin
  6. Android(安卓)代码规范 code style
  7. Android(安卓)显示手机电池的当前电量
  8. Android(安卓)代码提示无效

随机推荐

  1. Android(安卓)使用 第三方 Sweet Alert D
  2. JS判断客户端是否是iOS或者Android
  3. Android(安卓)NDK学习(1) 简介
  4. EditText 所有属性
  5. 】Android横竖屏总结
  6. Android(安卓)8.1 zygote创建新应用进程
  7. android之layout_toLeftOf和layout_toRig
  8. Android(安卓)Button字母自动全部大写的
  9. 相关约束参数的含义
  10. Android(安卓)2.2.2到Android(安卓)4.2.2