android为RadioButton动态添加style样式

            // 分类数组
            String [] titles_ = {"测试1", "测试2", "测试3", "测试4", "测试5",};
            // 初始化RadioGroup下的子元素
            if (null != titles_) {
                int size = titles_.length;
                for (int i = 0; i < size; i++) {
                    RadioButton rdbtn = (RadioButton) LayoutInflater.from(empView_).inflate(R.layout.tabmenu_radiobutton, null);
                    rdbtn.setId(i);
                    rdbtn.setText(titles_[i]);
                    radioGroup_.addView(rdbtn);
                }
            }

tabmenu_radiobutton.xml如下:

<?xml version="1.0" encoding="utf-8"?>
<RadioButton 
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/radioButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
    
</RadioButton>    

tabmenu_style.xml

<resources>

    <style name="radioButton">
    	<item name="android:layout_width">100dp</item>
    	<item name="android:layout_height">fill_parent</item>
    	<item name="android:layout_weight">1.0</item>
    	<item name="android:padding">10dp</item>
    	<item name="android:gravity">center</item>
    	<item name="android:button">@null</item>
    </style>

</resources>






































你可能感兴趣的:(android为RadioButton动态添加style样式)