Reputation: 16813
I have the following xml
file in my android app
. When user opens the app, the keyboard becomes active at the same time. Even though user has not even started in the EditText
.
How could I control keyboard? I want keyboard to appear when a user tap on the 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>
Upvotes: 0
Views: 193
Reputation: 2528
Modify your axml
file as follows:
<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" >
or do it with code:
var root = FindViewById<LinearLayout>(Resource.Id.mWellList);
root.RequestFocus();
as described here: https://forums.xamarin.com/discussion/1856/how-to-disable-auto-focus-on-edit-text
To hide the Keyboard:
Include:
using Android.Views.InputMethods;
and then:
InputMethodManager imm = (InputMethodManager) this.GetSystemService(Context.InputMethodService);
imm.HideSoftInputFromWindow(YourEditTextHere.WindowToken, 0);
Also check this thread for clearing focus on touch outside: EditText, clear focus on touch outside
Upvotes: 1
Reputation: 4917
Add in the manifest file inside the activity tag
android:windowSoftInputMode="stateAlwaysHidden"
like Below
<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>
Upvotes: 0