本文整理汇总了Java中android.widget.TimePicker.setCurrentHour方法的典型用法代码示例。如果您正苦于以下问题:Java TimePicker.setCurrentHour方法的具体用法?Java TimePicker.setCurrentHour怎么用?Java TimePicker.setCurrentHour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TimePicker
的用法示例。
在下文中一共展示了TimePicker.setCurrentHour方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import android.widget.TimePicker; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_time_selection);
Bundle extras = getIntent().getExtras();
setTitle(extras.getInt("title"));
//noinspection ConstantConditions
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, extras.getInt("color"))));
dtpTime = (TimePicker) findViewById(R.id.timePicker);
dtpTime.setIs24HourView(true);
timeSelection = GregorianCalendar.getInstance();
timeSelection.setTimeInMillis(extras.getLong("date"));
//noinspection deprecation
dtpTime.setCurrentHour(timeSelection.get(Calendar.HOUR_OF_DAY));
//noinspection deprecation
dtpTime.setCurrentMinute(timeSelection.get(Calendar.MINUTE));
}
示例2: onCreateDialogView
import android.widget.TimePicker; //导入方法依赖的package包/类
@Override
protected View onCreateDialogView() {
TimePicker tp = new TimePicker(getContext());
tp.setIs24HourView(DateFormat.is24HourFormat(getContext()));
tp.setOnTimeChangedListener(this);
originalHour = getHour();
originalMinute = getMinute();
if (originalHour >= 0 && originalMinute >= 0) {
tp.setCurrentHour(originalHour);
tp.setCurrentMinute(originalMinute);
}
return tp;
}
示例3: pickTime
import android.widget.TimePicker; //导入方法依赖的package包/类
/**
* 时间选择对话框
*
* @param con 上下文
* @param title 标题
* @param listener 选择事件
* @param cal 默认时间
*/
public static void pickTime(Context con, String title, Calendar cal, final OnTimeSetListener listener) {
LinearLayout ll = new LinearLayout(con);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
ll.setLayoutParams(layoutParams);
ll.setOrientation(LinearLayout.VERTICAL);
//添加一条线
LinearLayout line = new LinearLayout(con);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1);
line.setBackgroundColor(con.getResources().getColor(R.color.line));
line.setLayoutParams(lp);
ll.addView(line);
//添加选择器控件
final TimePicker timePicker = new TimePicker(con, null, themeId);
timePicker.setLayoutParams(layoutParams);
timePicker.setCurrentHour(cal.get(Calendar.HOUR_OF_DAY));
timePicker.setCurrentMinute(cal.get(Calendar.MINUTE));
timePicker.setIs24HourView(true);
ll.addView(timePicker);
QuickDialog.Builder builder = new QuickDialog.Builder(con);
builder.setContentView(ll);
builder.setTitle(title);
builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
listener.onTimeSet(timePicker, timePicker.getCurrentHour(), timePicker.getCurrentMinute());
}
});
builder.create().show();
}
示例4: onCreateContentView
import android.widget.TimePicker; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
protected View onCreateContentView(Bundle savedInstanceState) {
picker = new TimePicker(getContext());
if (savedInstanceState != null){
picker.setCurrentHour(savedInstanceState.getInt(HOUR));
picker.setCurrentMinute(savedInstanceState.getInt(MINUTE));
} else {
if (getArguments().containsKey(HOUR)) {
picker.setCurrentHour(getArguments().getInt(HOUR));
}
if (getArguments().containsKey(MINUTE)) {
picker.setCurrentMinute(getArguments().getInt(MINUTE));
}
}
if (getArguments().containsKey(VIEW_24_HOUR)) {
picker.setIs24HourView(getArguments().getBoolean(VIEW_24_HOUR));
} else {
picker.setIs24HourView(DateFormat.is24HourFormat(getContext())); // system default
}
picker.setOnTimeChangedListener(this);
return picker;
}
示例5: setTime
import android.widget.TimePicker; //导入方法依赖的package包/类
@SuppressWarnings("SameParameterValue")
public static ViewAction setTime(final int hour, final int minute) {
return new ViewAction() {
@Override
public void perform(UiController uiController, View view) {
TimePicker tp = (TimePicker) view;
if(android.os.Build.VERSION.SDK_INT < 23) {
//noinspection deprecation
tp.setCurrentHour(hour);
//noinspection deprecation
tp.setCurrentMinute(minute);
}
else {
tp.setHour(hour);
tp.setMinute(minute);
}
}
@Override
public String getDescription() {
return "Set the passed time into the TimePicker";
}
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isAssignableFrom(TimePicker.class);
}
};
}
示例6: onCreateDialogView
import android.widget.TimePicker; //导入方法依赖的package包/类
@Override
protected View onCreateDialogView() {
Context context = getContext();
TimePicker timePicker = new TimePicker(context);
timePicker.setIs24HourView(is24HourFormat(context));
timePicker.setOnTimeChangedListener(this);
timePicker.setCurrentHour(getHour());
timePicker.setCurrentMinute(getMinute());
return timePicker;
}