Фокус EditText открывает клавиатуру автоматически - PullRequest
1 голос
/ 29 октября 2011

Когда я начинаю активность входа в систему. у него есть два поля email и пароль. Электронная почта должна получить фокус, но не открывать клавиатуру автоматически, когда начинается действие.

<?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>

Ответы [ 2 ]

6 голосов
/ 29 октября 2011

Вы должны добавить атрибут

android:windowSoftInputMode="stateAlwaysHidden"

к вашей активности в AndroidManifest.xml

0 голосов
/ 14 сентября 2014

Этот метод подавляет программную клавиатуру, пока пользователь не коснется EditText

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