簡體   English   中英

鍵盤僅在用戶單擊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>

修改您的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,清除對觸摸外部的關注

活動標簽內添加清單文件

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM