Android 组件样式定制方法详解

2019-12-10 19:56:40王冬梅

 

 4.3使用样式。

在你xml中添加   即可(MyRadioButton是上面的命名)。

使用的布局实例如下:
 

  1. <?xml version="1.0" encoding="utf-8"?>  <RadioGroup xmlns:android="http://www.easck.com/apk/res/android" 
  2.   android:layout_width="fill_parent"    android:layout_height="fill_parent" 
  3.   android:background="#aaaaaa"    android:orientation="vertical" > 
  4.      <RadioButton 
  5.     style="@style/MyRadioButton"      android:layout_width="wrap_content" 
  6.     android:layout_height="50dip"      android:layout_marginTop="10dip" 
  7.     android:text="ABCD" />    
  8.   <RadioButton      style="@style/MyRadioButton" 
  9.     android:layout_width="wrap_content"      android:layout_height="50dip" 
  10.     android:layout_marginTop="10dip"      android:text="EFGH" /> 
  11.    </RadioGroup> 
?

效果图:

 

Android 组件样式定制方法详解

5、相关说明。

对于style.xml中为什么给background加个图片而把button的图片设置为@null。这点其实要看你个人需要:

①如果你需要的样式是点选以后整个背景都改变那么改background的样式就可以了,而且把button的样式设置成@null,如果不设置的话当然是系统默认的样式。
②如果你只是想把系统样式中的那个带圈的图给换点的话那么改button的样式就可以了。