Android用户界面 UI组件--TextView及其子类(五) DigitalClock,AnalogClock,RadioButton,CheckBox,ToggleButton汇总
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汇总的更多相关文章
- Android用户界面UI组件--AdapterView及其子类(五) Spinner和SpinnerAdapter
Spinner就是下拉框组件,可以自定义下拉布局样式,可以使用ArrayAdapter以及SpinnerAdapter适配 在Adapter中实现SpinnerAdapter,继承BaseAdapte ...
- Android用户界面 UI组件--TextView及其子类(三) EditView以及各种Span文字样式讲解
EditView和TextView的用法差不多,只是文字可编辑 小技巧: 设置EditText隐藏键盘 setInputType(0); 设置EditText不被输入法遮盖 getWindow() ...
- Android用户界面 UI组件--TextView及其子类(二) Button,selector选择器,sharp属性
1.XML文件中的OnClick 属性可以指定在Activity中处理点击事件的方法,Activity中必须定义该属性指定的值作为方法的名字且有一个View类型的参数,表示此物件被点击. 2.使用se ...
- Android用户界面 UI组件--TextView及其子类(一) TextView
1.TextView android:autoLink设置是否当文本为URL链接/email/电话号码/map时,文本显示为可点击的链接.可选值(none /web/email/phone/map/a ...
- Android用户界面 UI组件--TextView及其子类(四) Chronometer计时器
Chronometer是一个简单的定时器,你可以给它一个开始时间,并以此定时,或者如果你不给它一个开始时间,它将会使用你的时间通话开始.默认情况下它会显示在当前定时器的值的形式“分:秒”或“H:MM: ...
- Android用户界面 UI组件--AdapterView及其子类(一) ListView及各种Adapter详解
ListView就是列表组件,一般通过继承ListActivity使用系统提供的ListView. 所有的AdapterView组件都需要有一个对应的Adapter作为适配器来显示列表中元素的布局方式 ...
- Android用户界面UI组件--AdapterView及其子类(四) GridView
GridView常用的XML属性: android:columnWidth 设置列的宽度. android:horizontalSpacing 两列之间的间距. android:numColum ...
- Android用户界面UI组件--AdapterView及其子类(三) ExpandableListView
ExpandableListView: List中的每一项可以展开收缩. 一种伸缩式的ListView. android:cacheColorHint="#00000000" 这个 ...
- Android用户界面 UI组件--ImageView及其子类ImageButton,QuickContactBadge附带Draw9Patch工具说明
1.ImageView 常用属性: android:src 设置可绘制对象作为 ImageView 显示的内容 android:cropToPadding 如果设置为true,图片裁剪到保留该Imag ...
随机推荐
- [ lucene高级 ] 研讨如何进行Lucene的分布式应用
http://www.cnblogs.com/huangfox/archive/2010/10/15/1852206.html Lucene是个高度优化的倒转索引搜索引擎.它将倒转的索引存储在定制的文 ...
- LSJ_NHibernate第三章 IDAL,DAL,BLL
前言: 做项目(面向数据编程),首先必须了解业务,这是核心,不懂业务写出来的代码毫无意义.业务我这里分为两种,简单业务操作,复杂业务操作,我以他们操作表的界限进行区分,假设我更新一条数据,只操作了一张 ...
- jasper
package jasper; import java.util.ArrayList;import java.util.HashMap;import java.util.Map; import net ...
- Kettle中通过触发器方式实现数据 增量更新
在使用Kettle进行数据同步的时候, 共有 1.使用时间戳进行数据增量更新 2.使用数据库日志进行数据增量更新 3.使用触发器+快照表 进行数据增量更新 今天要介绍的是第3中方法. 实验的思路是这样 ...
- [python]pep8编码规范
一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在操作符的后边敲回车.3 类 ...
- 关于iOS上的静态库
最近再进行项目的真机调试,然后发现了一个天坑.就此研究了一些iOS上的静态库的使用: 首先我们是直接拿一个可以运行的项目来制作静态库的,网上大部分都是先创建静态库然后再写内容,看看我的方法. 1.把子 ...
- iOS Crash文件的解析
iOS Crash文件的解析 开发程序的过程中不管我们已经如何小心,总是会在不经意间遇到程序闪退.脑补一下当你在一群人面前自信的拿着你的App做功能预演的时候,流畅的操作被无情地Crash打断.联想起 ...
- 注释玩转webapi
using System; using System.Collections.Generic; using System.Net.Http.Formatting; using System.Web.H ...
- 10.10_魔兽账号,OSC代码托管演示,研究SQL别忘记了,git
(1)juedui8456juedui456chixin0769魔兽世界账号112288 (2)EasyXls.开源中国推出 PaaS@OSC 代码演示和运行平台.git.oschina.coding ...
- ZEngine游戏框架需求稿
早在2013就开始接触cocos2dx游戏框架,觉得的使用框架对于游戏开发者来说有些不方便.我便想在cocos2dx的框架基础之上实现ZEngine库,方便开发者编辑动画,以及着重于对游戏逻辑的处理. ...