• RadioButton ---- 样式效果切换


    esdrawable adio_button_bg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@drawable/raido_button_checked" 
            android:state_checked="true"/>
        <item android:drawable="@android:color/transparent" />
    
    </selector>

    esvaluesstrings.xml

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="app_name">RadioButtonDemo</string>
        <string name="hello_world">Hello world!</string>
        <string name="menu_settings">Settings</string>
        <string name="radio_button_1">JAVA</string>
        <string name="radio_button_2">ASP.NET</string>
        <string name="radio_button_3">P H P</string>
    </resources>


    esvaluesstyles.xml

        <style name="RadioButtonStyles">
            <item name="android:layout_gravity">center_vertical</item>
            <item name="android:layout_height">fill_parent</item>
            <item name="android:layout_width">wrap_content</item>
            <item name="android:layout_weight">1</item>
            <item name="android:button">@null</item>
            <item name="android:background">@drawable/radio_button_bg</item> 
            <item name="android:gravity">center</item> 
        </style>


    esmenuactivity_radio_button_demo.xml

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        <item
            android:id="@+id/menu_settings"
            android:orderInCategory="100"
            android:showAsAction="never"
            android:title="@string/menu_settings"/>
    </menu>


    eslayoutactivity_radio_button_demo.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <RadioGroup
            android:id="@+id/radioGroup1"
            android:layout_width="fill_parent"
            android:layout_height="50dp"
            android:background="@drawable/x_proposal_tab_bg"
            android:orientation="horizontal" >
    
            <RadioButton
                android:id="@+id/radio0"
                style="@style/RadioButtonStyles"          
                android:text="@string/radio_button_1" />
    
            <RadioButton
                android:id="@+id/radio1"
                style="@style/RadioButtonStyles"
                android:text="@string/radio_button_2" />
    
            <RadioButton
                android:id="@+id/radio2"
                style="@style/RadioButtonStyles"
                android:text="@string/radio_button_3" />
        </RadioGroup>
    
    </RelativeLayout>


    RadioButtonDemoActivity.java

    public class RadioButtonDemoActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_radio_button_demo);
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.activity_radio_button_demo, menu);
            return true;
        }
    
    }

     DEMO下载地址:http://download.csdn.net/detail/androidsj/5865317

  • 相关阅读:
    【原】iOS学习之XML与JSON两种数据结构比较和各自底层实现
    ios 10 访问设置问题
    蛇形输出
    苹果内购流程详解
    iOS多线程比较
    App iCON 尺寸
    学习网站
    c++ lesson 一(命名空间输入输出)
    iOS中WebSocket的使用
    MAC TXT文本
  • 原文地址:https://www.cnblogs.com/androidsj/p/3235798.html
Copyright © 2020-2023  润新知