zapotec
zapotec

Reputation: 2638

SoftKeyboard on EditText

This is my layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Introduzca codigo de comercial"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="400dp"
    android:layout_height="190dp"
    android:layout_above="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="60dp"
    android:src="@drawable/logo" />

<EditText
    android:id="@+id/textocontrasena"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/textView1"
    android:layout_marginTop="30dp"
    android:ems="5" >
</EditText>

<Button
    android:id="@+id/loginlogin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_below="@+id/textocontrasena"
    android:layout_marginTop="20dp"
    android:background="@drawable/xmlbotonzarko"
    android:text="Login"
    android:textColor="#FFF"
    android:textSize="19sp"
    android:textStyle="bold" />

My problem is that the softkeyboard is opening automatically when I enter on the Activity. What I want is the softkeyboard to open just when the user clicks on the EditText(not before).

Thanks!

Upvotes: 3

Views: 235

Answers (3)

koleanu
koleanu

Reputation: 495

put the focus on another view, and try to add this for your TextEdit View android:focusable="true" android:focusableInTouchMode="true"

Example change focus : ((yourView)findViewById(R.id.your_id)).requestFocus();

Upvotes: 0

Mxyk
Mxyk

Reputation: 10698

Edit your Activity code in your Android Manifest that is associated with this layout by adding either:

android:configChanges="keyboardHidden|orientation"

or,

android:windowSoftInputMode="stateHidden"

so that it would look something like:

<activity
    android:name="my.package.name.MyActivity"
    android:label="MyActivity"
    android:configChanges="keyboardHidden|orientation"  <!-- Pick one of -->
    android:windowSoftInputMode="stateHidden" />        <!-- these two   -->

This should prevent the softkeyboard from automatically opening up on activity start.

Upvotes: 2

K_Anas
K_Anas

Reputation: 31466

Place this inside the manifest for your activity: android:windowSoftInputMode="stateHidden"

Upvotes: 1

Related Questions