2011-10-28 117 views
1

當我開始登錄活動。它有兩個字段的電子郵件和密碼。電子郵件應獲得焦點,但在活動開始時不會自動打開鍵盤。EditText焦點自動打開鍵盤

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/splash_background_gradient" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:layout_marginBottom="10dip" 
     android:layout_marginTop="10dip" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/SplashLogo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginBottom="40dip" 
      android:src="@drawable/splash_logo" /> 

     <EditText 
      android:id="@+id/EmailAddress" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginLeft="25dp" 
      android:layout_marginRight="25dp" 
      android:hint="Email Address" 
      android:maxLines="1" android:nextFocusRight="@+id/Password"> 


     </EditText> 

     <EditText 
      android:id="@+id/Password" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginLeft="25dp" 
      android:layout_marginRight="25dp" 
      android:layout_marginTop="5dip" 
      android:hint="Password" 
      android:inputType="textPassword" /> 

     <Button 
      android:id="@+id/Login" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginLeft="25dp" 
      android:layout_marginRight="25dp" 
      android:layout_marginTop="10dip" 
      android:background="@drawable/login_button_selector" 
      android:text="@string/login" /> 

     <TextView 
      android:id="@+id/ForgotPassword" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginLeft="28dp" 
      android:layout_marginRight="28dp" 
      android:layout_marginTop="10dip" 
      android:text="@string/forgot_password" 
      android:textColor="#000000" 
      android:textSize="7pt"/> 
    </LinearLayout> 

</ScrollView> 

回答

6

你應該在AndroidManifest.xml

+0

該死的這種技術抑制了軟鍵盤。 。一直在尋找放入XML的東西。非常感謝 :) –

0

屬性

android:windowSoftInputMode="stateAlwaysHidden" 

添加到您的活動,直到用戶觸摸一個EditText

InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(YourClass.INPUT_METHOD_SERVICE); 
if (inputMethodManager != null) { // protection 
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
} 
相關問題