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();  
            }  
              
        }  
          
    };  
}

相关推荐