我有一个DatePicker,我禁用了SpinnerView,现在只使用CalendarView.但它从星期日开始,我想使用星期一作为一周的第一天.我怎么能改变呢?我猜测第一天将取决于手机设置,但在我的瑞士手机上仍然是错误的......
我没有找到任何set方法或任何XML命令.
<DatePicker
android:id="@+id/date_picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" />
Run Code Online (Sandbox Code Playgroud)
和
DatePicker datePicker = (DatePicker) convertView.findViewById(R.id.date_picker);
datePicker.setSpinnersShown(false);
Run Code Online (Sandbox Code Playgroud)
- - - - - - 编辑: - - - - - -
我试图改变语言环境:
Locale.setDefault(Locale.GERMAN);
Run Code Online (Sandbox Code Playgroud)
但这并没有改变任何以太.所以我读了android-17.android.widget.DatePicker.java,我发现了:
public DatePicker(Context context, AttributeSet attrs, int defStyle) {
//...
// initialization based on locale
setCurrentLocale(Locale.getDefault());
//...
}
/**
* Sets the current locale.
*
* @param locale The current locale.
*/
private void setCurrentLocale(Locale locale) {
if (locale.equals(mCurrentLocale)) {
return;
}
mCurrentLocale = locale;
mTempDate = getCalendarForLocale(mTempDate, locale); …Run Code Online (Sandbox Code Playgroud) 例如,当我在18:00创建这个timePicker(下面)时,timePicker的timeValue将是06:00.在19:44-> 07:44 ...因此在从AM/PM切换到24h模式后,它没有移动到正确的当前小时.我怎么能改变呢?我的目标是timePicker显示创建它的当前时间.就像我在AM/PM模式下使用它时一样.
TimePicker timePicker = (TimePicker) convertView.findViewById(R.id.time_picker);
timePicker.setIs24HourView(true);
Run Code Online (Sandbox Code Playgroud)
对于糟糕的表述,希望你能理解我的问题.否则就问.
更新:
public class ChooseTimeViewDialog extends AlertDialog {
protected Context context;
public ChooseTimeViewDialog(final Context context) {
super(context);
this.context = context;
}
public void onCreate(Bundle savedInstanceState) {
LayoutInflater inflater = this.getLayoutInflater();
View convertView = inflater.inflate(R.layout.dialog_choose_time_view, null);
setContentView(convertView);
setTitle(R.string.title_dialog_choose_time_view);
final TimePicker taskTimePicker = (TimePicker) convertView.findViewById(R.id.dctv_task_time_picker);
taskTimePicker.setIs24HourView(true);
setButton(DialogInterface.BUTTON_POSITIVE, "Choose", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int hour = taskTimePicker.getCurrentHour();
int minute = taskTimePicker.getCurrentMinute();
Calendar cal = new GregorianCalendar();
cal.set(0, …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试创建一个益智游戏,其中我有一个网格,并且每个单元格都应该能够在触摸时显示视觉(并且仅视觉)指示。因此,我打算在自定义视图中使用ViewGroupOverlay(使用 getOverlay()):
在每个CellView
@Override
public boolean onTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.overlay, null);
gridView.getOverlay().add(myView);
}
if(event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
gridView.getOverlay().clear();
}
return super.onTouchEvent(event);
}
Run Code Online (Sandbox Code Playgroud)
其中 'gridView' 是父级(一个 FrameLayout 包含一个 GridLayout,该 GridLayout 包含多个 CellView(它们是 RelativeLayout));)。但我认为这并不重要......
目前用于overview.xml(只是虚拟代码)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddd090d">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Test" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
可悲的是,覆盖视图没有出现在任何地方。
但是,如果我在'onTouchEvent'中使用drawable和以下代码尝试它,它会起作用......但我需要视图而不是drawable来工作......
Drawable myIcon = …Run Code Online (Sandbox Code Playgroud)