用RadioButton实现选项卡效果并设置样式

<RadioGroup
	android:id="@+id/query_type"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:checkedButton="@+id/query_type_fuzzy"
	android:orientation="horizontal" android:gravity="center_vertical|center_horizontal">
	<RadioButton
		android:id="@+id/query_type_fuzzy"
		android:text="fuzzy"
		/>
	<RadioButton
		android:id="@+id/query_type_precise"
		android:text="precise"
		/>	
</RadioGroup>			
<TableLayout
	android:id="@+id/test_tabel_1"
	android:layout_width="fill_parent"
    android:layout_height="wrap_content"
	android:orientation="horizontal">
	<TableRow android:gravity="center_vertical|center_horizontal">
		<Button
			android:id="@+id/button_ok"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="@string/button_ok"/>
		<Button
			android:id="@+id/button_cancel"
			android:layout_width="wrap_content"
			android:layout_height="wrap_content"
			android:text="@string/button_cancel"/>
	</TableRow>		
</TableLayout>
<TableLayout
	android:id="@+id/test_tabel_2"
	android:layout_width="fill_parent"
    android:layout_height="wrap_content"
	android:orientation="horizontal" android:visibility="gone">
	<TableRow android:gravity="center_vertical|center_horizontal">
		<TextView
			android:text="page 2"
			android:layout_width="fill_parent"
    		android:layout_height="wrap_content"
			/>
	</TableRow>		
</TableLayout>

RadioGroup rg = (RadioGroup).findViewById(R.id.query_type);
		rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				Log.i(TAG, "RadioGroop: " + checkedId);
				TableLayout tl1 = (TableLayout)dialog.findViewById(R.id.test_tabel_1);
				TableLayout tl2 = (TableLayout)dialog.findViewById(R.id.test_tabel_2);
				if(R.id.query_type_fuzzy == checkedId){
					tl1.setVisibility(TableLayout.VISIBLE);
					tl2.setVisibility(TableLayout.GONE);
				}else if(R.id.query_type_precise == checkedId){
					tl2.setVisibility(TableLayout.VISIBLE);
					tl1.setVisibility(TableLayout.GONE);
				}
			}
			
		});

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
	<item android:state_enabled="true" android:state_checked="true"
		android:drawable="@drawable/checked" />
	<item android:state_enabled="true" android:state_checked="false"
		android:drawable="@drawable/unchecked" />
</selector>

check和checknull分别为选中和位选中的图片。
1然后在你的布局文件中,RadioButton 布局
1设置android:button = "@drawable/radiobutton",就可以了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值