【发布时间】:2012-06-15 08:21:36
【问题描述】:
致各位
我正在尝试让一个简单的 NumberPicker 在 AlertDialog 中工作。问题是每当我增加/减少数字选择器中的值时,键盘都会激活。
有很多帖子描述了这个问题,但没有一个建议有效。 我试过了:
android:configChanges="keyboard|keyboardHidden"
和
inputManager.hideSoftInputFromWindow(currentView.getWindowToken(), 0);
还有
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
我曾尝试在初始化之前和之后调用这些函数(dialog.show ())、按键事件(显然使用侦听器)等,但到目前为止没有运气。
完整代码:
popup.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<NumberPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myNumber"
android:configChanges="keyboard|keyboardHidden"
/>
</RelativeLayout>
以及调用函数:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
View view = getLayoutInflater().inflate(R.layout.popup, null);
builder.setView (view);
final AlertDialog dialog = builder.create ();
NumberPicker picker = (NumberPicker) view.findViewById(R.id.myNumber);
picker.setMinValue(0);
picker.setMaxValue(999);
dialog.getWindow().
setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
dialog.show();
任何帮助表示赞赏
巴里
【问题讨论】:
标签: android dialog android-widget keyboard android-softkeyboard