1.main.xml【组建设置】
2.创建drawable文件--selector.xml文件--对应RadioButton属性
-----------------------------------------1---------------------------------------
<!-- xml四个tab -->
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/beijingview" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:visibility="gone" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioGroup
android:id="@+id/main_tab_group"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:layout_gravity="bottom"
android:background="#FFF0F5"
android:gravity="bottom"
android:orientation="horizontal"
android:weightSum="4" >
<RadioButton
android:id="@+id/main_tab_first"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:checked="true"
android:textSize="11dp"
android:drawableTop="@drawable/selector_tab_home"
android:gravity="center"
android:text="办公" />
<RadioButton
android:id="@+id/main_tab_second"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:textSize="11dp"
android:drawableTop="@drawable/selector_tab_find"
android:gravity="center"
android:text="我的任务" />
<RadioButton
android:id="@+id/main_tab_thread"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:button="@null"
android:textSize="11dp"
android:drawableTop="@drawable/selector_tab_search"
android:gravity="center"
android:text="即时通讯" />
<RadioButton
android:id="@+id/main_tab_settings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:drawableTop="@drawable/selector_tab_profile"
android:gravity="center"
android:textSize="11dp"
android:text="设置" />
</RadioGroup>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#00000000"
android:orientation="horizontal" >
<!-- 显示提醒信息的button android:layout_weight=1 是3个butto,平分手机界面的宽度 -->
<Button
android:id="@+id/bt1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible"
android:background="#00000000" />
<!-- 占位置的button,以便适应不同分辨率手机 -->
<Button
android:layout_width="0dp"
android:id="@+id/bt2"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" />
<!-- 占位置的button,以便适应不同分辨率手机 -->
<Button
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="@+id/bt3"
android:visibility="invisible" />
<Button
android:layout_width="0dp"
android:id="@+id/bt4"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
-----------------------------------------2---------------------------------------
selector.xml文件
-------------------------------------第一个xml------------------------------
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/working" android:state_pressed="false" android:state_selected="true" />
<item android:drawable="@drawable/working" android:state_checked="true" android:state_pressed="false" />
<item android:drawable="@drawable/working1" />
</selector>
-------------------------------------第二个xml------------------------------
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/minetask" android:state_pressed="false" android:state_selected="true" />
<item android:drawable="@drawable/minetask" android:state_checked="true" android:state_pressed="false" />
<item android:drawable="@drawable/minetask1" />
</selector>
------------------------------------第三个xml-------------------------------
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/nowsend" android:state_pressed="false" android:state_selected="true" />
<item android:drawable="@drawable/nowsend" android:state_checked="true" android:state_pressed="false" />
<item android:drawable="@drawable/nowsend1" />
</selector>
------------------------------------第四个xml-------------------------------
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/set" android:state_pressed="false" android:state_selected="true" />
<item android:drawable="@drawable/set" android:state_checked="true" android:state_pressed="false" />
<item android:drawable="@drawable/set1" />
</selector>
public class MainActivity extends TabActivity implements
OnCheckedChangeListener {
private TabHost tabHost;// 声明tabhost对象
RadioGroup radioGroup;// 主界面布局
FrameLayout updatatv;
// 声明ActionBar的自定义xml布局控件
View actionbarLayout;
TextView tv;
ImageButton left_imbt, right_imbt;
private int flag = 0;// 判断ImagButton的Enable-false/true
int back;
Button button1, button2, button3, button4;
String NUM = "3";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
private void init() {
radioGroup = (RadioGroup) this.findViewById(R.id.main_tab_group);
radioGroup.setOnCheckedChangeListener(this);
button1 = (Button) findViewById(R.id.bt1);
button2 = (Button) findViewById(R.id.bt2);
button3 = (Button) findViewById(R.id.bt3);
button4 = (Button) findViewById(R.id.bt4);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.main_tab_first:
tv.setText("办公");
flag = 0;
setOnclick(flag);
left_imbt.setVisibility(View.INVISIBLE);
right_imbt.setVisibility(View.INVISIBLE);
tabHost.setCurrentTabByTag("办公");
break;
case R.id.main_tab_second:
tv.setText("我的任务");
flag = 0;
setOnclick(flag);
// 设置按钮图片
left_imbt.setVisibility(View.INVISIBLE);
right_imbt.setVisibility(View.INVISIBLE);
tabHost.setCurrentTabByTag("我的任务");
break;
case R.id.main_tab_thread:
tv.setText("即时通讯");
flag = 1;
right_imbt.setEnabled(true);
setOnclick(flag);
// 设置按钮图片
left_imbt.setVisibility(View.INVISIBLE);
right_imbt.setBackgroundResource(R.drawable.addgt);
tabHost.setCurrentTabByTag("即时通讯");
break;
case R.id.main_tab_settings:
tv.setText("设置");
flag = 0;
setOnclick(flag);
left_imbt.setVisibility(View.INVISIBLE);
right_imbt.setVisibility(View.INVISIBLE);
tabHost.setCurrentTabByTag("设置");
break;
}
}
/**
* 设置TabHost属性
*/
private void getTabView() {
tabHost = this.getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, WorkOfficeActivity.class);
spec = tabHost.newTabSpec("办公").setIndicator("办公").setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MineSActivity.class);
spec = tabHost.newTabSpec("我的任务").setIndicator("我的任务")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, InstantMsgActivity.class);
spec = tabHost.newTabSpec("即时通讯").setIndicator("即时通讯")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, InfoSetActivity.class);
spec = tabHost.newTabSpec("设置").setIndicator("设置").setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}