DigitalClock和AnalogClock两个时钟类

可以为DigitalClock设置背景图片,自定义时针,秒针,分针的样式

例子:

<?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:gravity="center_horizontal"
>
<!-- 定义模拟时钟 -->
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<!-- 定义数字时钟 -->
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14pt"
android:textColor="#f0f"
android:drawableRight="@drawable/ic_launcher"
/>
<!-- 定义模拟时钟,并使用自定义表盘、时针图片 -->
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dial="@drawable/watch"
android:hand_minute="@drawable/hand"
/>
</LinearLayout>

运行结果:

RadioGroup单选组RadioGroup.

OnCheckedChangeListener()监听单选按钮点击事件

注意:各个RadioButton之间的id不能重复,RadioButton的id与RadioGroup的id也不能重复.

RadioButton

android:button="@null"

去除RadioButton前面的圆点

ToggleButton

常用属性:

android:textOff未选中时按钮的文本

android:textOn选中时按钮的文本

android:checked="true"  该状态用于设置初始状态,true表示开,false表示关,若没有设置该状态则默认为关android:background="@drawable/toggleselector"  如果要想改变ToggleButton开和关的图片,则需要设置这个属性,toggleselector将放到下面,是一个selector配置文件监听事件:CompoundButton.OnCheckedChangeListener()

重要补充:在xml中设置文字有时候间距什么的不好控制,这个时候可以把文字写在图片里面,在xml中把texton和textoff都设置为“”

实例:

package com.light.study.android;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.Toast; public class MainActivity extends Activity {
private RadioGroup gender;
private CheckBox swimming, reading, basketball; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
initListener();
} private void init() {
gender = (RadioGroup) findViewById(R.id.myRadioGroup);
swimming = (CheckBox) findViewById(R.id.swimming);
reading = (CheckBox) findViewById(R.id.reading);
basketball = (CheckBox) findViewById(R.id.basketball);
} private void initListener() {
gender.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.female) {
Toast.makeText(MainActivity.this, "性别:女", Toast.LENGTH_LONG)
.show();
} else if (checkedId == R.id.male) {
Toast.makeText(MainActivity.this, "性别:男", Toast.LENGTH_LONG)
.show();
}
}
});
swimming.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "爱好:游泳", Toast.LENGTH_LONG)
.show();
}
});
reading.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "爱好:阅读", Toast.LENGTH_LONG)
.show();
}
});
basketball.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "爱好:篮球", Toast.LENGTH_LONG)
.show();
}
});
} }
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="性别:" />
<!-- 建立一个RadioGroup --> <RadioGroup
android:id="@+id/myRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" > <!-- 第一个RadioButton --> <RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<!-- 第二个RadioButton --> <RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
</RadioGroup>
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="爱好:" /> <CheckBox
android:id="@+id/swimming"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="游泳" /> <CheckBox
android:id="@+id/basketball"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="篮球" /> <CheckBox
android:id="@+id/reading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="阅读" />
</LinearLayout> </LinearLayout>

效果图:

												

Android用户界面 UI组件--TextView及其子类(五) DigitalClock,AnalogClock,RadioButton,CheckBox,ToggleButton汇总的更多相关文章

  1. Android用户界面UI组件--AdapterView及其子类(五) Spinner和SpinnerAdapter

    Spinner就是下拉框组件,可以自定义下拉布局样式,可以使用ArrayAdapter以及SpinnerAdapter适配 在Adapter中实现SpinnerAdapter,继承BaseAdapte ...

  2. Android用户界面 UI组件--TextView及其子类(三) EditView以及各种Span文字样式讲解

    EditView和TextView的用法差不多,只是文字可编辑 小技巧: 设置EditText隐藏键盘  setInputType(0); 设置EditText不被输入法遮盖  getWindow() ...

  3. Android用户界面 UI组件--TextView及其子类(二) Button,selector选择器,sharp属性

    1.XML文件中的OnClick 属性可以指定在Activity中处理点击事件的方法,Activity中必须定义该属性指定的值作为方法的名字且有一个View类型的参数,表示此物件被点击. 2.使用se ...

  4. Android用户界面 UI组件--TextView及其子类(一) TextView

    1.TextView android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none /web/email/phone/map/a ...

  5. Android用户界面 UI组件--TextView及其子类(四) Chronometer计时器

    Chronometer是一个简单的定时器,你可以给它一个开始时间,并以此定时,或者如果你不给它一个开始时间,它将会使用你的时间通话开始.默认情况下它会显示在当前定时器的值的形式“分:秒”或“H:MM: ...

  6. Android用户界面 UI组件--AdapterView及其子类(一) ListView及各种Adapter详解

    ListView就是列表组件,一般通过继承ListActivity使用系统提供的ListView. 所有的AdapterView组件都需要有一个对应的Adapter作为适配器来显示列表中元素的布局方式 ...

  7. Android用户界面UI组件--AdapterView及其子类(四) GridView

    GridView常用的XML属性: android:columnWidth  设置列的宽度. android:horizontalSpacing  两列之间的间距.  android:numColum ...

  8. Android用户界面UI组件--AdapterView及其子类(三) ExpandableListView

    ExpandableListView: List中的每一项可以展开收缩. 一种伸缩式的ListView. android:cacheColorHint="#00000000" 这个 ...

  9. Android用户界面 UI组件--ImageView及其子类ImageButton,QuickContactBadge附带Draw9Patch工具说明

    1.ImageView 常用属性: android:src 设置可绘制对象作为 ImageView 显示的内容 android:cropToPadding 如果设置为true,图片裁剪到保留该Imag ...

随机推荐

  1. YII数据库操作(CURD操作)

    数据库操作 获得模型对象 $model = 模型名::model();或$model = new 模型名(); 1.查询多条记录(返回值:二维数组) $result = $model->find ...

  2. nofollow标签如何使用

    “nofollow”的意思是不传递权重,向网站站长提供了一种方式,即告诉搜索引擎“不要追踪此网页上的链接”或“不要追踪此特定链接”. nofllow的形式 1.<meta name=" ...

  3. jQuery中的html,val,text区别

    在项目开发中,写jQuery代码有时候会搞混淆一下东西,现在写一下demo来列出jQuery的.html(),.text(),.val()的区别. 1. html()取得第一个匹配元素的内容,简单来说 ...

  4. Java 十六进制转十进制

    public static int hexToDecimal(String hex) { int decimalValue = 0; for (int i = 0; i < hex.length ...

  5. 使用CLK.AspNet.Identity提供以角色为基础的访问控制(RBAC)

    使用CLK.AspNet.Identity提供以角色为基础的访问控制(RBAC) 程序代码下载 程序代码下载:点此下载 前言 ASP.NET Identity是微软所贡献的开源项目,用来提供ASP.N ...

  6. Spring 对JDBC的支持(JdbcTemplate)

    Spring对数据库的操作,使用JdbcTemplate对象 需要引入相关的jar文件 如版本:(Spring核心jar包就不列了) spring-jdbc-3.2.5.RELEASE.jar spr ...

  7. IOS 学习笔记 2015-03-24 OC-API-网络访问-案例一

    // // WPSuggest.h // OC-API-网络访问 // // Created by wangtouwang on 15/3/24. // Copyright (c) 2015年 wan ...

  8. IOS 学习笔记 2015-03-22 OC-API-日期

    一 API 1 NSdate 2 NSDateFormatter 二 适用场景 1 获取当前日期 2 增加时间差 3 比较时间差 4 返回较早时间 5 日期格式话 6 日期转字符串 7 字符串转日期 ...

  9. ubuntu 安装phpmyadmin

    参考文章: http://www.111cn.net/database/mysql/43957.htm    access错误的解决方法 1 首先下载  去官网下载phpmyadmin 2  然后直接 ...

  10. phpstorm使用技巧

    确实很好用,不过还是要看一些方法 转自:http://blog.sina.com.cn/s/blog_488193d70102vk7e.html 2, 关联DOC文档: 右键External Libr ...