以前用Fragment模仿过微信底部导航 不过最近一个简单的项目准备用TabHost来做底部导航 所以回顾了一下TabHost的知识,做了一个简单的用TabHost来模仿微信导航的demo 因为图片的都是用以前的图片东西 需要的可以看Fragment之模仿微信界面 所以只贴出关键代码 效果如下图:
<?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="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="0.0dip"
android:layout_weight="1.0" >
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
</TabWidget>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/black"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/talk"
style="@style/rbt_bottom"
android:drawableTop="@drawable/take_bottom"
android:text="@string/talk" />
<RadioButton
android:id="@+id/address"
style="@style/rbt_bottom"
android:drawableTop="@drawable/adrress_bottom"
android:text="@string/address" />
<RadioButton
android:id="@+id/find"
style="@style/rbt_bottom"
android:drawableTop="@drawable/find_bottom"
android:text="@string/find" />
<RadioButton
android:id="@+id/me"
style="@style/rbt_bottom"
android:drawableTop="@drawable/me_bottom"
android:text="@string/me" />
</RadioGroup>
</LinearLayout>
</TabHost><?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/n_address_l" android:state_checked="true" android:state_enabled="true"/>
<item android:drawable="@drawable/n_address_h"/>
</selector>package com.android.xiong.bkclient;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.TabHost;
@SuppressWarnings("deprecation")
public class MainActivity extends TabActivity implements
OnCheckedChangeListener {
private TabHost tabHost;
private Intent addressIntent;
private Intent meIntent;
private Intent takeIntent;
private Intent findIntent;
private RadioButton findBt;
private RadioButton addressBt;
private RadioButton meBt;
private RadioButton takeBt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhostmain);
addressIntent = new Intent(this, AddressActivity.class);
meIntent = new Intent(this, MeActivity.class);
takeIntent = new Intent(this, TakeActivity.class);
findIntent = new Intent(this, FindActivity.class);
findBt = (RadioButton) findViewById(R.id.find);
addressBt = (RadioButton) findViewById(R.id.address);
meBt = (RadioButton) findViewById(R.id.me);
takeBt = (RadioButton) findViewById(R.id.talk);
tabHost =getTabHost();
tabHost.addTab(tabHost.newTabSpec("take").setIndicator("take")
.setContent(takeIntent));
tabHost.addTab(tabHost.newTabSpec("address").setIndicator("address")
.setContent(addressIntent));
tabHost.addTab(tabHost.newTabSpec("find").setIndicator("find")
.setContent(findIntent));
tabHost.addTab(tabHost.newTabSpec("me").setIndicator("me")
.setContent(meIntent));
findBt.setOnCheckedChangeListener(this);
meBt.setOnCheckedChangeListener(this);
takeBt.setOnCheckedChangeListener(this);
addressBt.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton view, boolean ischeak) {
if (ischeak) {
switch (view.getId()) {
case R.id.talk:
tabHost.setCurrentTabByTag("take");
break;
case R.id.find:
tabHost.setCurrentTabByTag("find");
break;
case R.id.me:
tabHost.setCurrentTabByTag("me");
break;
case R.id.address:
tabHost.setCurrentTabByTag("address");
break;
default:
break;
}
}
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.xiong.bkclient"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="com.android.xiong.bkclient.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.android.xiong.bkclient.AddressActivity"></activity>
<activity android:name="com.android.xiong.bkclient.FindActivity"></activity>
<activity android:name="com.android.xiong.bkclient.MeActivity"></activity>
<activity android:name="com.android.xiong.bkclient.TakeActivity"></activity>
</application>
</manifest>
TabHost底部导航知识回顾之模仿微信导航,布布扣,bubuko.com
原文:http://blog.csdn.net/x605940745/article/details/23302221