键盘只在用户单击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>

按如下方式修改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,清除焦点触摸外面

活动标签中添加manifest文件

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>

相关内容

最新更新