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. INI文件的读写

    public class INIoperation { string inipath = Utils.GetMapPath("/Integration/Sync/set.ini") ...

  2. Asp.net自制模板框架

    最近在做个包含了大量重复样式的控件的网站. 如果用MVC的话,我可以针对每个需要单独块编辑的Model写一个局部视图. 然后根据不同逻辑需求拼起来.用现成MVC框架非常容易做到. 但环境是3.5的最高 ...

  3. C10K问题2

    http://blog.csdn.net/zhoudaxia/article/details/12920993 是时候让 Web 服务器同时处理一万客户端了,你不觉得吗?毕竟,现在的 Web 是一个大 ...

  4. httphandler与httpmodule区别

    1.配置不同: <httpModules> <!--name表示类名,BtEd2k.UILogic表示命名空间--> <add name="Common&quo ...

  5. objective-c ios webkit 本地存储local-storage

    我有一个Cocoa / Objective-C的应用程序,它嵌入了一个WebKit的web视图.我需要打开的数据库支持和本地存储.我知道这是可以做到-我有它在Safari中工作-但我无法找到如何设置这 ...

  6. Spring 对JDBC的支持(JdbcTemplate)

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

  7. 享元模式(咖啡屋)【java与模式】

    package com.javapatterns.flyweight.coffeeshop; public class Flavor extends Order { private String fl ...

  8. 2016.08.07计算几何总结测试day2

    T1 bzoj: [Usaco2010 OPen]Triangle Counting 数三角形 看到这个题n那么大, 于是想到极角排序搞一搞,然而排完序后立马懵逼,完全不知道接下来应该怎么写.... ...

  9. 理解Java中的前期绑定和后期绑定

    前期绑定,在程序执行前根据编译时类型绑定,调用开销较小,如C语言只有前期绑定这种方法调用. 后期绑定,是指在运行时根据对象的类型进行绑定,又叫动态绑定或运行时绑定.实现后期绑定,需要某种机制支持,以便 ...

  10. android 开源框架推荐

    同事整理的 android 开源框架,个个都堪称经典.32 个赞! 1.volley 项目地址 https://github.com/smanikandan14/Volley-demo (1)  JS ...