主界面的XML
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    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" >        <FrameLayout            android:id="@android:id/tabcontent"            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1" >        </FrameLayout>        <TabWidget            android:id="@android:id/tabs"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0"            android:visibility="gone" >        </TabWidget>        <LinearLayout            android:layout_width="match_parent"            android:layout_height="60dp" >            <RelativeLayout                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1"                android:background="@drawable/tab_texture"                 android:id="@+id/rl_Cy">                <RadioButton                    android:id="@+id/rBtn_Cy"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerInParent="true"                    android:background="@null"                    android:button="@null"                    android:drawableTop="@drawable/cy_selector"                    android:gravity="center"                    android:text="@string/str_cy"                    android:textColor="@drawable/txtcol_selector"                    android:textSize="13sp" />            </RelativeLayout>            <RelativeLayout                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1"                android:background="@drawable/tab_texture"                 android:id="@+id/rl_Aq">                <RadioButton                    android:id="@+id/rBtn_Aq"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerInParent="true"                    android:background="@null"                    android:button="@null"                    android:drawableTop="@drawable/aq_selector"                    android:gravity="center"                    android:text="@string/str_aq"                    android:textColor="@drawable/txtcol_selector"                    android:textSize="13sp" />            </RelativeLayout>            <RelativeLayout                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_weight="1"                android:background="@drawable/tab_texture"                 android:id="@+id/rl_Ys">                <RadioButton                    android:id="@+id/rBtn_Ys"                    android:layout_width="wrap_content"                    android:layout_height="wrap_content"                    android:layout_centerInParent="true"                    android:background="@null"                    android:button="@null"                    android:drawableTop="@drawable/ys_selector"                    android:gravity="center"                    android:text="@string/str_ys"                    android:textColor="@drawable/txtcol_selector"                    android:textSize="13sp" />            </RelativeLayout>                    </LinearLayout>    </LinearLayout></TabHost>

主界面,Java代码
package com.example.test_x360;import android.os.Bundle;import android.app.TabActivity;import android.content.Intent;import android.widget.CompoundButton;import android.widget.RadioButton;import android.widget.RelativeLayout;import android.widget.TabHost;import android.widget.CompoundButton.OnCheckedChangeListener;public class MainActivity extends TabActivity implementsOnCheckedChangeListener {private RelativeLayout rl_Cy;private RelativeLayout rl_Aq;private RelativeLayout rl_Ys;private RadioButton rBtn_Cy;private RadioButton rBtn_Aq;private RadioButton rBtn_Ys;// 定义标签名private static final String TAB_TAG_CY = "cyTag";private static final String TAB_TAG_AQ = "aqTag";private static final String TAB_TAG_YS = "ysTag";private TabHost mHost;private Intent cyIntent;private Intent aqIntent;private Intent ysIntent;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();setContent();setTabs();}private void initView() {rl_Cy = (RelativeLayout) findViewById(R.id.rl_Cy);rl_Aq = (RelativeLayout) findViewById(R.id.rl_Aq);rl_Ys = (RelativeLayout) findViewById(R.id.rl_Ys);rBtn_Cy = (RadioButton) findViewById(R.id.rBtn_Cy);rBtn_Aq = (RadioButton) findViewById(R.id.rBtn_Aq);rBtn_Ys = (RadioButton) findViewById(R.id.rBtn_Ys);rBtn_Cy.setOnCheckedChangeListener(this);rBtn_Aq.setOnCheckedChangeListener(this);rBtn_Ys.setOnCheckedChangeListener(this);}/**设置标签对应内容*/private void setContent() {cyIntent = new Intent(MainActivity.this, CyActivity.class);aqIntent = new Intent(MainActivity.this, AqActivity.class);ysIntent = new Intent(MainActivity.this, YsActivity.class);}private void setTabs() {// 获取TabHost对象mHost = getTabHost();// 添加TabSpecmHost.addTab(mHost.newTabSpec(TAB_TAG_CY).setContent(cyIntent).setIndicator(""));mHost.addTab(mHost.newTabSpec(TAB_TAG_AQ).setContent(aqIntent).setIndicator(""));mHost.addTab(mHost.newTabSpec(TAB_TAG_YS).setContent(ysIntent).setIndicator(""));// 设置默认显示标签mHost.setCurrentTabByTag(TAB_TAG_CY);// 设置默认选中按钮rBtn_Cy.setChecked(true);}@Overridepublic void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {switch (buttonView.getId()) {case R.id.rBtn_Cy:if (isChecked) {//显示当前点击项对应的标签内容mHost.setCurrentTabByTag(TAB_TAG_CY);//其余的RadioButton选中状态清除rBtn_Aq.setChecked(false);rBtn_Ys.setChecked(false);rl_Cy.setBackgroundResource(R.drawable.tab_pressed);} else {rl_Cy.setBackgroundResource(R.drawable.tab_texture);}break;case R.id.rBtn_Aq:if (isChecked) {mHost.setCurrentTabByTag(TAB_TAG_AQ);rBtn_Cy.setChecked(false);rBtn_Ys.setChecked(false);rl_Aq.setBackgroundResource(R.drawable.tab_pressed);} else {rl_Aq.setBackgroundResource(R.drawable.tab_texture);}break;case R.id.rBtn_Ys:if (isChecked) {mHost.setCurrentTabByTag(TAB_TAG_YS);rBtn_Aq.setChecked(false);rBtn_Cy.setChecked(false);rl_Ys.setBackgroundResource(R.drawable.tab_pressed);} else {rl_Ys.setBackgroundResource(R.drawable.tab_texture);}break;}}}

更多相关文章

  1. Android 简单的账号密码登陆界面(IO流)
  2. 主界面监听返回键,退出程序
  3. 写信息的界面
  4. android用ViewPager实现欢迎界面
  5. Android framwork 锁屏界面开发 笔记
  6. Android添加横线和竖线分割界面
  7. Android之模仿微信登陆界面(二)
  8. Android 高仿QQ 登陆界面
  9. 小编程(三):用户登录注册界面开发及用户信息管理案例代码详解

随机推荐

  1. Android 应用程序获得版本号
  2. Android通过Http连接MySQL 实现登陆/注册
  3. 三十五、android adb命令详解
  4. Android O - 为什么要引入HIDL
  5. Android缩放drawable
  6. 11月28号
  7. 关于android:configChanges="keyboardHid
  8. 享受 Android 应用程序的 Java 技术盛宴
  9. react native for android 包名修改
  10. Android Studio运行main方法报错 SourceS