note-42 custom radioButton
from:
http://blog.csdn.net/wanglong0537/article/details/6434728
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/search_bg" > <RadioGroup android:gravity="center" android:layout_gravity="bottom" android:orientation="horizontal" android:id="@+id/searchRadioGroup" android:layout_width="fill_parent" android:layout_height="wrap_content" > <RadioButton android:textSize="17.0sp" android:id="@+id/searchRadioShare" android:tag="radio_button0" android:text="搜索微博" android:layout_weight="1" style="@style/CustomLeftRadioBtn"> </RadioButton> <RadioButton android:textSize="17.0sp" android:id="@+id/searchRadioUser" android:tag="radio_button1" android:text="搜索用户" android:layout_weight="1" style="@style/CustomRightRadioBtn"> </RadioButton> </RadioGroup> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <resources> <mce:style name="CustomLeftRadioBtn"><!-- <item name="android:button">@null</item> <item name="android:drawableLeft">@drawable/search_radio_1</item> <item name="android:background">@drawable/search_left</item> <item name="android:gravity">center_vertical</item> --></mce:style><style name="CustomLeftRadioBtn" mce_bogus="1"> <item name="android:button">@null</item> <item name="android:drawableLeft">@drawable/search_radio_1</item> <item name="android:background">@drawable/search_left</item> <item name="android:gravity">center_vertical</item> </style> <mce:style name="CustomRightRadioBtn"><!-- <item name="android:button">@null</item> <item name="android:drawableLeft">@drawable/search_radio_1</item> <item name="android:background">@drawable/search_right</item> <item name="android:gravity">center_vertical</item> --></mce:style><style name="CustomRightRadioBtn" mce_bogus="1"> <item name="android:button">@null</item> <item name="android:drawableLeft">@drawable/search_radio_1</item> <item name="android:background">@drawable/search_right</item> <item name="android:gravity">center_vertical</item> </style> </resources>
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class RadioButtonDemo extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button searchRadioShare = (Button) findViewById(R.id.searchRadioShare); Button searchRadioUser = (Button) findViewById(R.id.searchRadioUser); searchRadioShare.setOnClickListener(l); searchRadioUser.setOnClickListener(l); } private View.OnClickListener l = new OnClickListener(){ @Override public void onClick(View v) { if(v.getId()==R.id.searchRadioShare){ Toast.makeText(RadioButtonDemo.this, "搜索微博", Toast.LENGTH_LONG).show(); }else{ Toast.makeText(RadioButtonDemo.this, "搜索用户", Toast.LENGTH_LONG).show(); } } }; }
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28