Android课程---日历选择器和时间选择器
package com.hanqi.test5; import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton; public class UIActivity1 extends AppCompatActivity { ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ui1);
//单选框
RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rg); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
if (checkedId == R.id.rb3) //rb3设定为正确答案
{
Toast.makeText(UIActivity1.this, "选对了", Toast.LENGTH_LONG).show();
}
RadioButton rb = (RadioButton) findViewById(checkedId);
Toast.makeText(UIActivity1.this, rb.getText(), Toast.LENGTH_LONG).show();
}
}); //复选框
CheckBox cb_st = (CheckBox)findViewById(R.id.cb_st);
cb_st.setOnCheckedChangeListener(new CBOnCheckedChangListenter() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { }
}); cb_st.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); CheckBox cb_jc = (CheckBox)findViewById(R.id.cb_jc);
cb_jc.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); CheckBox cb_xt = (CheckBox)findViewById(R.id.cb_xt);
cb_xt.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); CheckBox cb_xhx = (CheckBox)findViewById(R.id.cb_xhx);
cb_xhx.setOnCheckedChangeListener(new CBOnCheckedChangListenter()); iv =(ImageView)findViewById(R.id.iv); ToggleButton tob =(ToggleButton)findViewById(R.id.tob);
tob.setOnCheckedChangeListener(new TOnCheckedChangeListenter());
Switch sw =(Switch)findViewById(R.id.sw);
sw.setOnCheckedChangeListener(new TOnCheckedChangeListenter());
DatePicker dp_1 = (DatePicker)findViewById(R.id.dp_1); dp_1.init(2000, 0, 1, new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Toast.makeText(UIActivity1.this,year+"-"+(monthOfYear+1)+"-"+dayOfMonth,Toast.LENGTH_SHORT).show();
}
});
TimePicker tp_1 =(TimePicker)findViewById(R.id.tp_1);
tp_1.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(UIActivity1.this,hourOfDay + ":" + minute,Toast.LENGTH_SHORT).show();
}
});
}
private class TOnCheckedChangeListenter implements CompoundButton.OnCheckedChangeListener{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked)
{
iv.setImageResource(R.drawable.on); //设置图片来源
}
else
{
iv.setImageResource(R.drawable.off);
}
}
} private class CBOnCheckedChangListenter implements CompoundButton.OnCheckedChangeListener
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
CheckBox cb = (CheckBox)buttonView; if (isChecked) {
Toast.makeText(UIActivity1.this, "选中了" + cb.getText(), Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(UIActivity1.this, "取消了" + cb.getText(), Toast.LENGTH_LONG).show();
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
tools:context="com.hanqi.test5.UIActivity1"
android:scrollbars="none"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择Android的开发语言是什么?"/> <RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/rg"> <RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C++"
android:id="@+id/rb1"
android:layout_marginRight="30dp"
android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:id="@+id/rb2"
android:layout_marginRight="30dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="JAVA"
android:id="@+id/rb3"
android:layout_marginRight="30dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C#"
android:id="@+id/rb4" />
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择字体效果"/> <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="宋体"
android:id="@+id/cb_st"
android:checked="true"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加粗"
android:id="@+id/cb_jc" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="斜体"
android:id="@+id/cb_xt" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下划线"
android:id="@+id/cb_xhx" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#f0f"
android:scaleType="centerCrop"
android:src="@drawable/yuantu"
android:alpha="0.3"
android:id="@+id/iv1"/><!--alpha:图片透明度,值在0和1之间-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/off"
android:id="@+id/iv"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="打开"
android:textOff="关闭"
android:id="@+id/tob"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开关"
android:textOff="关"
android:textOn="开"
android:id="@+id/sw"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn=""
android:textOff=""
android:background="@drawable/mybutton"
android:id="@+id/tob1"/>
<AnalogClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" /><!--表盘型-->
<DigitalClock
android:layout_width="wrap_content"
android:layout_height="wrap_content" /><!--数字型-->
<DatePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:startYear="2000"
android:endYear="2016"
android:minDate="1/1/2000"
android:maxDate="1/1/2016"
android:id="@+id/dp_1"
android:calendarViewShown="false"></DatePicker>
<!--日期选择器 calendarViewShown:日历是否显示只对版本4.0起作用-->
<TimePicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tp_1"></TimePicker><!--时间选择器-->
<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"></CalendarView><!--日历显示器--> </LinearLayout> </ScrollView>
显示效果图:
Android课程---日历选择器和时间选择器的更多相关文章
- Android复制iPhone日期和时间选择器
看效果图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGluZ2xvbmd4aW4yNA==/font/5a6L5L2T/fontsize/400/fi ...
- Android 仿iPhone的日期时间选择器
可选只选择日期,也可以同时选择时间 只选择日期的情况 同时选择日期和时间的情况 关键代码: findViewById(R.id.selectDateButton).setOnClickListener ...
- Android——图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟、图片透明度、滚动和时间选择器
activity_ui1.xml dth="wrap_content" android:layout_height="wrap_content" android ...
- 转:【微信小程序常见问题】下拉框选择器设置picker属性。(包括:城市、日期和时间选择器)
1.picker写法(支持日期Date.时间Time和城市自定义) wxml文件 <picker bindchange="bindPickerChange" value=&q ...
- Android日期时间选择器实现以及自定义大小
本文主要讲两个内容:1.如何将DatePicker和TimePicker放在一个dialog里面:2.改变他们的宽度: 问题1:其实现思路就是自定义一个Dialog,然后往里面同时放入DatePick ...
- Android零基础入门第57节:日期选择器DatePicker和时间选择器TimePicker
原文:Android零基础入门第57节:日期选择器DatePicker和时间选择器TimePicker 在实际开发中,经常会遇见一些时间选择器.日期选择器.数字选择器等需求,那么从本期开始来学习And ...
- Android 开发笔记___时间选择器---timePicker
像datepicker一样,也有timepicker. 同样有timepickerdialog 所用到的方法还是一样,监听时间选择器的变化. package com.example.alimjan.h ...
- android 可以精确到秒级的时间选择器
android自带的时间选择器只能精确到分,但是对于某些应用要求选择的时间精确到秒级,此时只有自定义去实现这样的时间选择器了.下面介绍一个可以精确到秒级的时间选择器. 先上效果图: 下面是工程目录: ...
- android 开发 时间选择器TimePicker的使用
android系统自带时间控件:DatePicker 日期显示控件 DatePickerDialog 日期对话框控件TimePicker 时间显示控件 TimePickerDialog 时间对话框控件 ...
随机推荐
- ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)
题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...
- Zookeeper 分布式环境搭建
一.前期环境 安装概览 IP Host Name Software 192.168.23.128 ae01 JDK 1.7 192.168.23.129 ae02 JDK 1. ...
- java基础内容
此文作java语法基础的起始页,负责总结和目录引导 想我开始接触java语法也有比较长时间了(大概是2015年十月份),到现在(2016-10-25)为止还未系统的学习总结基础语法,亡羊补牢吧,回过头 ...
- BZOJ4504 : K个串
从左往右枚举右端点,用一棵线段树维护每个左端点的去重后的区间和. 那么对于$a[r]$,需要在$[pre[a[r]]+1,r]$里区间加上$a[r]$. 将线段树可持久化,并维护区间最大值,就可以在线 ...
- pig相关
1. 重命名pig job name: 在Pig脚本中的一开始处,写上这一句: set job.name 'This is my job'; 2. 设置pig参数: 允许pig时,输入如下: pig ...
- UVa 2197 & 拆点分环费用流
题意: 给你一个带权有向图,选择一些边组成许多没有公共边的环,使每个点都在k个环上,要求代价最小. SOL: 现在已经养成了这种习惯,偏题怪题都往网络流上想... 怎么做这题呢... 对我们看到每个点 ...
- ROW_NUMBER() OVER函数的基本用法
转自:http://www.cnblogs.com/icebutterfly/archive/2009/08/05/1539657.html 语法:ROW_NUMBER() OVER(PARTITIO ...
- js+css立体旋转
纯 CSS3 制作可口可乐罐 这个效果相信大家很多人看过了,纯css实现的立体可口可乐罐,看起来相当高大上~ 于是今天我这小菜鸟试着研究下,稍微遗憾的是,没有看到源码,还是直接F12吧,貌似实现也不 ...
- 【BZOJ】1115: [POI2009]石子游戏Kam
http://www.lydsy.com/JudgeOnline/problem.php?id=1115 题意:n堆石子,个数是从左到右单增.每一次可以从任意堆取出任意石子,但要保持单增这个性质.问先 ...
- 通过/etc/rc.local实现开机自动拉起服务
添加服务到/etc/rc.local 如自动拉起apache服务: /etc/rc.local: #!/bin/sh # # This script will be executed *after* ...