问题描述
以前有人问过这个问题,但当时的答案似乎不再适用于 Android Studio,否则我遗漏了一些东西.
This question has been asked before, but the answers from back then, doesn't seem to work in Android Studio anymore, or else i'm missing something.
我希望在您按下编辑文本区域时显示一个 timePicker 对话框,以在 editText 中设置时间.但是,由于某种原因,普通键盘在按下时会弹出.我没有收到任何错误,尽管它似乎仍然不起作用.
I want a timePicker dialog to show up when you press the edit text area, to set the time in the editText. However, for some reason, the normal keyboard simply pops up when pressed. I'm not getting any errors, though it still doesn't seem to work.
代码如下:
final EditText Edit_Time = (EditText) findViewById(R.id.time_view_edit);
Edit_Time.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(TimeActivity.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
Edit_Time.setText( selectedHour + ":" + selectedMinute);
}
}, hour, minute, true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
editText 的 xml 部分:
the xml part of editText:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/time_view_edit"
android:text="20:00"
android:layout_weight="1"/>
如果有人可以提供帮助,那么非常感谢,谢谢!
If anyone can help, then it's much appreciated, Thanks!
推荐答案
将这些属性添加到 xml 中的 EditText
标记以禁用键盘弹出
Add these properties to your EditText
tag in xml to disable keyboard popping up
android:editable="false"
和
android:focusable="false"
更新:
android:editable="false"
现在已弃用.使用 android:inputType="none"
代替或在代码中:
android:editable="false"
is deprecated now.use android:inputType="none"
instead or in the code:
editText.setEnabled(false);
这篇关于按 EditText 时的 TimePicker 对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!