解决方法在manifest文件中吧them的值修改为them.black;即可;
或者在定义tabhost时在content中应用VIEW实现,把要给按钮实现的布局在view中布好,view就是定义的一个layout 代码如下
tab_home tab_wo tab_tucao 分别为底部按钮的菜单
完整代码我已上传资源页
http://download.csdn.net/detail/u012373815/9011009
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
@SuppressWarnings("deprecation")
public classMainActivity extends Activity {
private TabHost tabhost;
@SuppressLint("InflateParams")
@Override
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LocalActivityManageractivityGroup = newLocalActivityManager(this,
false);
activityGroup.dispatchCreate(savedInstanceState);
View hometab = (View) LayoutInflater.from(this).inflate(
R.layout.tab_shouye,null);
Viewgfriendtab = (View) LayoutInflater.from(this).inflate(
R.layout.tab_xinxi,null);
Viewtipstab = (View) LayoutInflater.from(this).inflate(
R.layout.tab_gongju,null);
Viewtoolstab = (View) LayoutInflater.from(this).inflate(
R.layout.tab_wo,null);
tabhost = (TabHost)findViewById(R.id.main_tabhost);
tabhost.setup(activityGroup);
//去掉底部菜单的分割线
tabhost.getTabWidget().setDividerDrawable(android.R.color.transparent);
// home
Intenthome_intent = newIntent(this,TowActivity.class);
tabhost.addTab(tabhost.newTabSpec("home").setIndicator(hometab)
.setContent(home_intent));
overridePendingTransition(android.R.anim.slide_in_left,
android.R.anim.slide_out_right);
Intentgfriend_intent = newIntent(this,ThreeActivity.class);
tabhost.addTab(tabhost.newTabSpec("gfriend").setIndicator(gfriendtab)
.setContent(gfriend_intent));
Intenttips_intent = newIntent(this,FourActivity.class);
tabhost.addTab(tabhost.newTabSpec("tips").setIndicator(tipstab)
.setContent(tips_intent));
Intenttools_intent = newIntent(this,FiveActivity.class);
tabhost.addTab(tabhost.newTabSpec("tools").setIndicator(toolstab)
.setContent(tools_intent));
}
}
总共四个tab的布局
其他三个与此相同 唯独background="@drawable/gongju"
不同
<?xml version="1.0"encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="20dp"
android:orientation="vertical" >
<TextView
android:id="@+id/tab_home"
android:layout_width="28dp"
android:layout_height="35dp"
android:layout_marginTop="9dp"
android:layout_marginLeft="20dp"
android:background="@drawable/gongju"
/>
</LinearLayout>
通过一个图片切换效果实现底部菜单的选中和非选中的区别 gongju1 gongju0 分别为选中和非选中显示的图片 其他三个与此相同只有图片不同
<?xml version="1.0"encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@drawable/gongju1"/>
<item
android:state_selected="false"
android:drawable="@drawable/gongju0"/>
</selector>