键盘仅在用户单击 EditText 时出现
Keyboard only appears when user clicks on EditText
我的 android app
中有以下 xml
文件。当用户打开应用程序时,键盘同时变为活动状态。即使用户甚至还没有在 EditText
开始。
如何控制键盘?我希望当用户点击 EditText
.
时出现键盘
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mList"
android:minWidth="25px"
android:minHeight="25px">
<EditText
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search" />
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/mListView" />
</LinearLayout>
在manifest文件中添加activity标签
android:windowSoftInputMode="stateAlwaysHidden"
喜欢下面
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
按如下方式修改您的 axml
文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mWellList"
android:minWidth="25px"
android:minHeight="25px"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
或使用代码:
var root = FindViewById<LinearLayout>(Resource.Id.mWellList);
root.RequestFocus();
如此处所述:https://forums.xamarin.com/discussion/1856/how-to-disable-auto-focus-on-edit-text
隐藏键盘:
包括:
using Android.Views.InputMethods;
然后:
InputMethodManager imm = (InputMethodManager) this.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(YourEditTextHere.WindowToken, 0);
同时检查此线程以清除外部触摸的焦点:EditText, clear focus on touch outside
我的 android app
中有以下 xml
文件。当用户打开应用程序时,键盘同时变为活动状态。即使用户甚至还没有在 EditText
开始。
如何控制键盘?我希望当用户点击 EditText
.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mList"
android:minWidth="25px"
android:minHeight="25px">
<EditText
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/search" />
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/mListView" />
</LinearLayout>
在manifest文件中添加activity标签
android:windowSoftInputMode="stateAlwaysHidden"
喜欢下面
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
按如下方式修改您的 axml
文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/mWellList"
android:minWidth="25px"
android:minHeight="25px"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >
或使用代码:
var root = FindViewById<LinearLayout>(Resource.Id.mWellList);
root.RequestFocus();
如此处所述:https://forums.xamarin.com/discussion/1856/how-to-disable-auto-focus-on-edit-text
隐藏键盘:
包括:
using Android.Views.InputMethods;
然后:
InputMethodManager imm = (InputMethodManager) this.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(YourEditTextHere.WindowToken, 0);
同时检查此线程以清除外部触摸的焦点:EditText, clear focus on touch outside