android时间选择器
A. (高分,Android)求一个时间选择控件,支持选择一段时间
Android 时间段选择
看看这个符合不
B. android怎么获取两个时间选择器的差
安卓系统的游戏和其他运用软件的下载和安装一般有2种方式:
第一种直接在网站或者论坛上下载,后缀名为APK的安装程序,然后复制到在机器上,用机器自带的APK安装器安装后就可以使用了;
第二种是先在电脑上安装第3方辅助软件,常用的有91手机助手、豌豆夹、G蛋等,我自己用的是91手机助手,就用它来说明。安装好以后,先运行软件,再用USB把机器和电脑联机,软件会自动识别机器,这样你就可以用辅助软件91手机助手,按功能或者类别来搜你想要的游戏和软件,找到可以用91手机助手下载,下载完了91手机助手会自动安装(第一种方式下载的安装文件,也可以用91手机助手安装)
C. android studio怎么添加两个日期选择器
1、创建xml页面(我的项目扣下来的,有的地方会报错要改)
java"><TextView
android:id="@+id/consultation_tv_birthdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/consultation_tv_sex"
android:layout_alignStart="@+id/consultation_tv_sex"
android:layout_alignTop="@+id/consultation_et_birthdate"
android:layout_marginTop="9dp"
android:text="出生日期:"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold"/>
<EditText
android:id="@+id/consultation_et_birthdate"
android:layout_width="260dp"
android:layout_height="40dp"
android:layout_alignLeft="@+id/consultation_et_sex"
android:layout_alignStart="@+id/consultation_et_sex"
android:layout_below="@+id/consultation_et_sex"
android:layout_marginTop="22dp"
android:background="@drawable/input_bg"
android:focusable="false"
android:ems="10"
android:inputType="textPersonName"
android:paddingLeft="15dp"
android:paddingRight="15dp"/>
<ImageView
android:id="@+id/consultation_iv_birthdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/consultation_et_id_card"
android:layout_alignEnd="@+id/consultation_et_birthdate"
android:layout_alignRight="@+id/consultation_et_birthdate"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
app:srcCompat="@android:drawable/ic_menu_today"/>
2、创建参数
详细
D. 安卓 怎样自定义一个时间选择器
实现的效果就是在同一个布局上显示日期选择和时间选择。
自定义一个类:
/DateTimePicker/src/com/wwj/datetimepicker/DateTimePickDialogUtil.java
package com.wwj.datetimepicker;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
/**
* 日期时间选择控件 使用方法: private EditText inputDate;//需要设置的日期时间文本编辑框 private String
* initDateTime="2012年9月3日 14:44",//初始日期时间值 在点击事件中使用:
* inputDate.setOnClickListener(new OnClickListener() {
*
* @Override public void onClick(View v) { DateTimePickDialogUtil
* dateTimePicKDialog=new
* DateTimePickDialogUtil(SinvestigateActivity.this,initDateTime);
* dateTimePicKDialog.dateTimePicKDialog(inputDate);
*
* } });
*
* @author
*/
public class DateTimePickDialogUtil implements OnDateChangedListener,
OnTimeChangedListener {
private DatePicker datePicker;
private TimePicker timePicker;
private AlertDialog ad;
private String dateTime;
private String initDateTime;
private Activity activity;
/**
* 日期时间弹出选择框构造函数
*
* @param activity
* :调用的父activity
* @param initDateTime
* 初始日期时间值,作为弹出窗口的标题和日期时间初始值
*/
public DateTimePickDialogUtil(Activity activity, String initDateTime) {
this.activity = activity;
this.initDateTime = initDateTime;
}
public void init(DatePicker datePicker, TimePicker timePicker) {
Calendar calendar = Calendar.getInstance();
if (!(null == initDateTime || "".equals(initDateTime))) {
calendar = this.getCalendarByInintData(initDateTime);
} else {
initDateTime = calendar.get(Calendar.YEAR) + "年"
+ calendar.get(Calendar.MONTH) + "月"
+ calendar.get(Calendar.DAY_OF_MONTH) + "日 "
+ calendar.get(Calendar.HOUR_OF_DAY) + ":"
+ calendar.get(Calendar.MINUTE);
}
datePicker.init(calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH), this);
timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
}
/**
* 弹出日期时间选择框方法
*
* @param inputDate
* :为需要设置的日期时间文本编辑框
* @return
*/
public AlertDialog dateTimePicKDialog(final EditText inputDate) {
LinearLayout dateTimeLayout = (LinearLayout) activity
.getLayoutInflater().inflate(R.layout.common_datetime, null);
datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker);
timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker);
init(datePicker, timePicker);
timePicker.setIs24HourView(true);
timePicker.setOnTimeChangedListener(this);
ad = new AlertDialog.Builder(activity)
.setTitle(initDateTime)
.setView(dateTimeLayout)
.setPositiveButton("设置", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
inputDate.setText(dateTime);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
inputDate.setText("");
}
}).show();
onDateChanged(null, 0, 0, 0);
return ad;
}
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
onDateChanged(null, 0, 0, 0);
}
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// 获得日历实例
Calendar calendar = Calendar.getInstance();
calendar.set(datePicker.getYear(), datePicker.getMonth(),
datePicker.getDayOfMonth(), timePicker.getCurrentHour(),
timePicker.getCurrentMinute());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
dateTime = sdf.format(calendar.getTime());
ad.setTitle(dateTime);
}
/**
* 实现将初始日期时间2012年07月02日 16:45 拆分成年 月 日 时 分 秒,并赋值给calendar
*
* @param initDateTime
* 初始日期时间值 字符串型
* @return Calendar
*/
private Calendar getCalendarByInintData(String initDateTime) {
Calendar calendar = Calendar.getInstance();
// 将初始日期时间2012年07月02日 16:45 拆分成年 月 日 时 分 秒
String date = spliteString(initDateTime, "日", "index", "front"); // 日期
String time = spliteString(initDateTime, "日", "index", "back"); // 时间
String yearStr = spliteString(date, "年", "index", "front"); // 年份
String monthAndDay = spliteString(date, "年", "index", "back"); // 月日
String monthStr = spliteString(monthAndDay, "月", "index", "front"); // 月
String dayStr = spliteString(monthAndDay, "月", "index", "back"); // 日
String hourStr = spliteString(time, ":", "index", "front"); // 时
String minuteStr = spliteString(time, ":", "index", "back"); // 分
int currentYear = Integer.valueOf(yearStr.trim()).intValue();
int currentMonth = Integer.valueOf(monthStr.trim()).intValue() - 1;
int currentDay = Integer.valueOf(dayStr.trim()).intValue();
int currentHour = Integer.valueOf(hourStr.trim()).intValue();
int currentMinute = Integer.valueOf(minuteStr.trim()).intValue();
calendar.set(currentYear, currentMonth, currentDay, currentHour,
currentMinute);
return calendar;
}
/**
* 截取子串
*
* @param srcStr
* 源串
* @param pattern
* 匹配模式
* @param indexOrLast
* @param frontOrBack
* @return
*/
public static String spliteString(String srcStr, String pattern,
String indexOrLast, String frontOrBack) {
String result = "";
int loc = -1;
if (indexOrLast.equalsIgnoreCase("index")) {
loc = srcStr.indexOf(pattern); // 取得字符串第一次出现的位置
} else {
loc = srcStr.lastIndexOf(pattern); // 最后一个匹配串的位置
}
if (frontOrBack.equalsIgnoreCase("front")) {
if (loc != -1)
result = srcStr.substring(0, loc); // 截取子串
} else {
if (loc != -1)
result = srcStr.substring(loc + 1, srcStr.length()); // 截取子串
}
return result;
}
}
/DateTimePicker/src/com/wwj/datetimepicker/DateTimePickerActivity.java
package com.wwj.datetimepicker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
/**
* 时间拾取器界面
*
* @author wwj_748
*
*/
public class DateTimePickerActivity extends Activity {
/** Called when the activity is first created. */
private EditText startDateTime;
private EditText endDateTime;
private String initStartDateTime = "2013年9月3日 14:44"; // 初始化开始时间
private String initEndDateTime = "2014年8月23日 17:44"; // 初始化结束时间
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 两个输入框
startDateTime = (EditText) findViewById(R.id.inputDate);
endDateTime = (EditText) findViewById(R.id.inputDate2);
startDateTime.setText(initStartDateTime);
endDateTime.setText(initEndDateTime);
startDateTime.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
DateTimePickerActivity.this, initEndDateTime);
dateTimePicKDialog.dateTimePicKDialog(startDateTime);
}
});
endDateTime.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
DateTimePickerActivity.this, initEndDateTime);
dateTimePicKDialog.dateTimePicKDialog(endDateTime);
}
});
}
}
自定义界面:
/DateTimePicker/res/layout/common_datetime.xml
<?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:orientation="vertical" >
<DatePicker
android:id="@+id/datepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false" />
<TimePicker
android:id="@+id/timepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
E. android日期选择器 根据时间判断是上午还是下午 仿ios
你直接获取当前日期和时间就可以判断了,将日期改为24小时制就行。
F. Android这种时间选择器用什么控件
com.wheel中的WheelView是滑动控件的主类,如果需要更改显示效果可以更改这个类中的代码(比如字体显示大小等),drawable文件夹下是一些布局资源文件,是一些背景色的定义,time_picker.xml是这个时间选择对话框的layout文件 public class Main...
G. android自定义时间选择器,滑动选择日期,智能判断每月多少天
自定义一个类:
/DateTimePicker/src/com/wwj/datetimepicker/DateTimePickDialogUtil.java
[java] view plain
package com.wwj.datetimepicker;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
/**
* 日期时间选择控件 使用方法: private EditText inputDate;//需要设置的日期时间文本编辑框 private String
* initDateTime="2012年9月3日 14:44",//初始日期时间值 在点击事件中使用:
* inputDate.setOnClickListener(new OnClickListener() {
*
* @Override public void onClick(View v) { DateTimePickDialogUtil
* dateTimePicKDialog=new
* DateTimePickDialogUtil(SinvestigateActivity.this,initDateTime);
* dateTimePicKDialog.dateTimePicKDialog(inputDate);
*
* } });
*
* @author
*/
public class DateTimePickDialogUtil implements OnDateChangedListener,
OnTimeChangedListener {
private DatePicker datePicker;
private TimePicker timePicker;
private AlertDialog ad;
private String dateTime;
private String initDateTime;
private Activity activity;
/**
* 日期时间弹出选择框构造函数
*
* @param activity
* :调用的父activity
* @param initDateTime
* 初始日期时间值,作为弹出窗口的标题和日期时间初始值
*/
public DateTimePickDialogUtil(Activity activity, String initDateTime) {
this.activity = activity;
this.initDateTime = initDateTime;
}
public void init(DatePicker datePicker, TimePicker timePicker) {
Calendar calendar = Calendar.getInstance();
if (!(null == initDateTime || "".equals(initDateTime))) {
calendar = this.getCalendarByInintData(initDateTime);
} else {
initDateTime = calendar.get(Calendar.YEAR) + "年"
+ calendar.get(Calendar.MONTH) + "月"
+ calendar.get(Calendar.DAY_OF_MONTH) + "日 "
+ calendar.get(Calendar.HOUR_OF_DAY) + ":"
+ calendar.get(Calendar.MINUTE);
}
datePicker.init(calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH), this);
timePicker.setCurrentHour(calendar.get(Calendar.HOUR_OF_DAY));
timePicker.setCurrentMinute(calendar.get(Calendar.MINUTE));
}
/**
* 弹出日期时间选择框方法
*
* @param inputDate
* :为需要设置的日期时间文本编辑框
* @return
*/
public AlertDialog dateTimePicKDialog(final EditText inputDate) {
LinearLayout dateTimeLayout = (LinearLayout) activity
.getLayoutInflater().inflate(R.layout.common_datetime, null);
datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.datepicker);
timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.timepicker);
init(datePicker, timePicker);
timePicker.setIs24HourView(true);
timePicker.setOnTimeChangedListener(this);
ad = new AlertDialog.Builder(activity)
.setTitle(initDateTime)
.setView(dateTimeLayout)
.setPositiveButton("设置", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
inputDate.setText(dateTime);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
inputDate.setText("");
}
}).show();
onDateChanged(null, 0, 0, 0);
return ad;
}
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
onDateChanged(null, 0, 0, 0);
}
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// 获得日历实例
Calendar calendar = Calendar.getInstance();
calendar.set(datePicker.getYear(), datePicker.getMonth(),
datePicker.getDayOfMonth(), timePicker.getCurrentHour(),
timePicker.getCurrentMinute());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
dateTime = sdf.format(calendar.getTime());
ad.setTitle(dateTime);
}
/**
* 实现将初始日期时间2012年07月02日 16:45 拆分成年 月 日 时 分 秒,并赋值给calendar
*
* @param initDateTime
* 初始日期时间值 字符串型
* @return Calendar
*/
private Calendar getCalendarByInintData(String initDateTime) {
Calendar calendar = Calendar.getInstance();
// 将初始日期时间2012年07月02日 16:45 拆分成年 月 日 时 分 秒
String date = spliteString(initDateTime, "日", "index", "front"); // 日期
String time = spliteString(initDateTime, "日", "index", "back"); // 时间
String yearStr = spliteString(date, "年", "index", "front"); // 年份
String monthAndDay = spliteString(date, "年", "index", "back"); // 月日
String monthStr = spliteString(monthAndDay, "月", "index", "front"); // 月
String dayStr = spliteString(monthAndDay, "月", "index", "back"); // 日
String hourStr = spliteString(time, ":", "index", "front"); // 时
String minuteStr = spliteString(time, ":", "index", "back"); // 分
int currentYear = Integer.valueOf(yearStr.trim()).intValue();
int currentMonth = Integer.valueOf(monthStr.trim()).intValue() - 1;
int currentDay = Integer.valueOf(dayStr.trim()).intValue();
int currentHour = Integer.valueOf(hourStr.trim()).intValue();
int currentMinute = Integer.valueOf(minuteStr.trim()).intValue();
calendar.set(currentYear, currentMonth, currentDay, currentHour,
currentMinute);
return calendar;
}
/**
* 截取子串
*
* @param srcStr
* 源串
* @param pattern
* 匹配模式
* @param indexOrLast
* @param frontOrBack
* @return
*/
public static String spliteString(String srcStr, String pattern,
String indexOrLast, String frontOrBack) {
String result = "";
int loc = -1;
if (indexOrLast.equalsIgnoreCase("index")) {
loc = srcStr.indexOf(pattern); // 取得字符串第一次出现的位置
} else {
loc = srcStr.lastIndexOf(pattern); // 最后一个匹配串的位置
}
if (frontOrBack.equalsIgnoreCase("front")) {
if (loc != -1)
result = srcStr.substring(0, loc); // 截取子串
} else {
if (loc != -1)
result = srcStr.substring(loc + 1, srcStr.length()); // 截取子串
}
return result;
}
}
/DateTimePicker/src/com/wwj/datetimepicker/DateTimePickerActivity.java
[java] view plain
package com.wwj.datetimepicker;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
/**
* 时间拾取器界面
*
* @author wwj_748
*
*/
public class DateTimePickerActivity extends Activity {
/** Called when the activity is first created. */
private EditText startDateTime;
private EditText endDateTime;
private String initStartDateTime = "2013年9月3日 14:44"; // 初始化开始时间
private String initEndDateTime = "2014年8月23日 17:44"; // 初始化结束时间
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 两个输入框
startDateTime = (EditText) findViewById(R.id.inputDate);
endDateTime = (EditText) findViewById(R.id.inputDate2);
startDateTime.setText(initStartDateTime);
endDateTime.setText(initEndDateTime);
startDateTime.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
DateTimePickerActivity.this, initEndDateTime);
dateTimePicKDialog.dateTimePicKDialog(startDateTime);
}
});
endDateTime.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
DateTimePickerActivity.this, initEndDateTime);
dateTimePicKDialog.dateTimePicKDialog(endDateTime);
}
});
}
}
自定义界面:
/DateTimePicker/res/layout/common_datetime.xml
[html] view plain
<?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:orientation="vertical" >
<DatePicker
android:id="@+id/datepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false" />
<TimePicker
android:id="@+id/timepicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
H. android 时间选择器怎么设置不可选
先定义你的Edtext 然后为他定义一个点击事件 如 //Time 是Edtext的ID Time.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog(text6.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { QS.setText("起始日期:" + String.format("%d-%d-%d", year, monthOfYear + 1, dayOfMonth)); } //2016,1,1是弹出时间选择器的默认时间 }, 2016, 1, 2).show(); } }); 哪里不了解再问