如何在 android 中使用单选按钮实现 tabHost 的功能?
- 如何在顶部设计一个自定义单选按钮组,
- 这样就可以像我们在选项卡主机中那样单击该按钮....显示活动的功能
选项卡.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/rdb1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.33"
android:background="@android:color/white"
android:button="@null"
android:gravity="center"
android:text="Tab1"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="bold" />
<RadioButton
android:id="@+id/rdb2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.33"
android:background="@android:color/white"
android:button="@null"
android:gravity="center"
android:text="Tab2"
android:textColor="@android:color/black"
android:textSize="15sp"
android:textStyle="bold" />
</RadioGroup>
</LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<include layout="@layout/tabs"/>
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}