2012-07-27 68 views
0

這是我的佈局:SoftKeyboard上的EditText

<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" /> 

我的問題是,當我在活動進入softkeyboard自動打開。 我想要的只是當用戶點擊EditText(而不是之前)時打開的軟鍵盤。

謝謝!

+0

您正在測試哪個設備? – 2012-07-27 11:53:31

+0

看到這個答案http://stackoverflow.com/a/11542820/1289716 – MAC 2012-07-27 11:56:43

+0

可能重複[停止EditText獲得焦點在活動啓動?](http://stackoverflow.com/questions/1555109/stop-edittext-from -gaining-focus-at-activity-startup) – COD3BOY 2012-07-27 11:59:40

回答

1

將這個清單爲您的活動中:android:windowSoftInputMode="stateHidden"

+0

謝謝!這就是解決方案! – zapotec 2012-07-28 17:52:50

2

編輯在Android ManifestActivity代碼,通過添加與此佈局關聯或者:

android:configChanges="keyboardHidden|orientation" 

,或者

android:windowSoftInputMode="stateHidden" 

,這樣它看起來是這樣的:

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

這應該會自動阻止軟鍵盤開始活動開始。

+0

完美!它工作完美!非常感謝! – zapotec 2012-07-28 17:52:21

0

把重點放在另一個視圖,並嘗試添加這爲您的文字編輯查看android:focusable="true" android:focusableInTouchMode="true"

例如,變更重點:((yourView)findViewById(R .id.your_id))requestFocus()方法。