本例Light Theme 和下例Default Theme ,代码和资源部分几乎一模一样。都使用R.layout.controls_1的 Layout ,Controls1.java 和Controls2.java 差别只在类的名称。

controls_1.xml 定义了下面几种UI控件:Button,EditText,CheckBox,RadioButton,ToggleButton ,Spinner ,TextView 有的前面以有介绍,有的后面会有详细说明。

这里提一下 RadioButton ,RadioButton为单选钮,需要为一组单选钮定义一个组,组内单选钮只能有一个选中,组定义为RadioGroup,如:

<RadioGroup android:layout_width=”match_parent” android:layout_height=”wrap_content” android:orientation=”vertical”> <RadioButton android:id=”@+id/radio1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/controls_1_radiobutton_1″ /> <RadioButton android:id=”@+id/radio2″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/controls_1_radiobutton_2″ /> </RadioGroup>

此外,CheckBox 可以定义不同的风格,比如本例使用一个“星星”形状:

<CheckBox android:id=”@+id/star”
style=”?android:attr/starStyle”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:text=”@string/controls_1_star” />

其实大部分UI控件都可以自定义风格。

本例和下例一个使用“浅色”风格,一个使用缺省风格,这是通过在AndroidMainifest.xml 为Activity 定义了不同的风格,比如本例:

<activity android:name=”.view.Controls1″
android:label=”Views/Controls/1. Light Theme”
android:theme=”@android:style/Theme.Light”>
<intent-filter>
< action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.SAMPLE_CODE” />
< /intent-filter>
< /activity>

Controls->1. Light Theme_第1张图片" width="650" src="https://img.it610.com/image/product/19109d3e43a04d3094040be602ebfe12.jpg" height="466" style="border:1px solid black;">


更多相关文章

  1. 自定义EditText
  2. Android(安卓)浏览器设置中的搜索引擎
  3. android自定义dialog,软件键盘弹出挡住输入区域解决
  4. Android(安卓)framework自定义待机广播(可静态注册)
  5. Android(安卓)新控件学习
  6. android零碎学习记录之 TextSwithcer
  7. Android(安卓)在OnCreate()中获取控件高度与宽度
  8. Android(安卓)go 自定义静态广播接收不到的问题
  9. Android(安卓)UI设计中的三种特效

随机推荐

  1. android排版(布局)
  2. android WebView总结
  3. 很实用的android压缩图片的算法
  4. Android之Handler用法总结
  5. Android简介
  6. Android(安卓)TextView 如何判断是否已经
  7. 【Android进阶】android:configChanges属
  8. Android(安卓)4.4 KitKat 支持 u 盘功能
  9. android基本架构
  10. android 实现静默安装、卸载(图)