Phonespeedmain.xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabHost
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="65dip"
android:layout_margin="0dip"
android:layout_marginTop="-5dip"
android:layout_weight="0"
android:background="@drawable/img_backgra"
android:gravity="center" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background"/>
</LinearLayout>
</TabHost>
</LinearLayout>
public class DriverActivity extends TabActivity {
TabHost mTabhost;
TabWidget mTabWidget;
Intent intent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
setContentView(R.layout.phonespeedmain);
mTabhost = (TabHost) findViewById(android.R.id.tabhost);
mTabhost = getTabHost();
mTabWidget = mTabhost.getTabWidget();
mTabhost.setup(this.getLocalActivityManager());// 使用intent时,必须加上这句
// 设置当前选项卡
mTabhost.setCurrentTab(0);
phoneSpeed();//手机加速
systemInfo();//系统检测
changeTab(0);
////
//for(int i=0;i<2;i++){
//mTabWidget.getChildAt(0).setBackgroundResource(R.drawable.comm_btn_bg2_n);
//mTabWidget.getChildAt(1).setBackgroundResource(R.drawable.comm_btn_bg2_s);
//}
//
//监听选项卡实现切换卡布局页面
mTabhost.setOnTabChangedListener(new OnTabChangeListener() {
@Override
public void onTabChanged(String tabId) {
changeTab(mTabhost.getCurrentTab());
}
});
}// ---------------------------oncreate-----------------------------
private void changeTab(int curTab) {
for(int ii = 0;ii<mTabWidget.getChildCount();ii++){
updateTabBackground(curTab,ii);
}
}
这个代吗实现的是切换卡布局更换背景的功能,如果选中,就高亮显示,如果不点击,就发暗。
private void updateTabBackground(int curTab, int ii) {
View view = mTabWidget.getChildAt(ii);
view.setBackgroundResource(R.drawable.img_backgra);
if(curTab == ii){
switch (ii) {
case 0:
view.setBackgroundResource(R.drawable.img_backgra);
break;
case 1:
view.setBackgroundResource(R.drawable.img_backgra);
break;
}
}else{
switch (ii) {
case 0:
view.setBackgroundResource(R.drawable.backimg_fouce);
break;
case 1:
view.setBackgroundResource(R.drawable.backimg_fouce);
break;
}
}// TODO Auto-generated method stub
}
通过一个自定义布局,加一个一标签 ,实现手机加速的一个标签,并在点击标签,通过自定义intent 进入显示内容activity。
需要注意的是先加载布局,找到布局中的textView 加上标题手机加速,但是通过intent跳转的时,要加setup
private void phoneSpeed() {
//intent = new Intent(DriverActivity.this, PhoneSpeed.class);
//mTabhost.addTab(mTabhost
//.newTabSpec("one")
//.setIndicator("手机加速",getResources().getDrawable(R.drawable.phone_speed))
//.setContent(intent));
// mTabhost.setBackgroundResource(R.drawable.comm_btn_bg2_n);
View view = LayoutInflater.from(DriverActivity.this).inflate(R.layout.speed_tab, null);
TextView tv = (TextView) view.findViewById(R.id.speed_tab_title);
tv.setText("手机加速");
intent = new Intent(DriverActivity.this,PhoneSpeed.class);
ImageView iv = (ImageView) view.findViewById(R.id.speed_tab_imageview);
iv.setImageResource(R.drawable.phone_speed);
mTabhost.addTab(mTabhost.newTabSpec("手机加速").setIndicator(view).setContent(intent));
}
private void systemInfo() {
//intent = new Intent(DriverActivity.this, SystemFix.class);
//mTabhost.addTab(mTabhost
//.newTabSpec("two")
//.setIndicator("系统检测",getResources().getDrawable(R.drawable.phone_sys))
//.setContent(intent2));
mTabhost.setBackgroundResource(R.drawable.comm_btn_bg2_n);
Speed_tab.xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/img_backgra"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/speed_tab_imageview"
android:layout_width="fill_parent"
android:layout_height="35.0dip"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/speed_tab_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:gravity="center"
android:marqueeRepeatLimit="1"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="15dip" />
</LinearLayout>
2.通过布局加载一个tab
View view = LayoutInflater.from(DriverActivity.this).inflate(R.layout.speed_tab, null);
TextView tv = (TextView) view.findViewById(R.id.speed_tab_title);
tv.setText("系统检测");
intent = new Intent(DriverActivity.this,SystemFix.class);
ImageView iv = (ImageView) view.findViewById(R.id.speed_tab_imageview);
iv.setImageResource(R.drawable.phone_sys);
mTabhost.addTab(mTabhost.newTabSpec("系统检测").setIndicator(view).setContent(intent));
}
}
1.使用自定义布局,加载切换卡标签
如果内容是使用跳转到别一个activity时,在oncreate 方法中需要加上这句
mTabhost.setup(this.getLocalActivityManager());
2.去除ExpandableListView左边的下拉按钮android:groupIndicator="@null"
3.放在listview上的点击事件
注意listview 和 checkbox 点击事件,只能设置listview点击,把checkbox设为不可点击,要不会抢先点击事件。
/*<CheckBox
android:id="@+id/check"
android:clickable="false"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="23dp" />*/