2015-12-11 3 views
3

EditText заводит нас с ума! действительно!Проблема с Android EditText, неправильная EditText

У нас есть проблема на экране входа в систему для нашего приложения. Он содержит два EditTexts, но только первый (Имя пользователя) фокусируется, с помощью SoftKeyboard появляется только, если коснуться/щелкнуть имя пользователя EditText. После того, как щелкнули имя пользователя EditText и, следовательно, отображается SoftKeyboard, при касании/нажатии пароля EditText он отображается сфокусированным (курсор мигает в редакторе EditText), но ввод с клавиатуры будет вставлен в имя пользователя EditText.

Теперь смешная часть. Мы попытались отключить его и снова, с помощью экрана (нажав кнопку питания), а затем, удивляясь, все работает так, как ожидалось.

Мы что-то упускаем?

Мы пытались совсем все:

  • сплющенной иерархию вида
  • макета с содержащим видом только один линейного макета
  • фокусирующегося фокусируемым в сенсорном режиме
  • заливки удалить видовой экран от родительского ScrollView
  • Фрагменты для деятельности

Мы используем Android Design Support Library v23.1.1 и AppCompat библиотека v23.1.1

Screenshot of the login screen

LoginFragment.java

public class LoginFragment extends Fragment { 

private LoginButton fbLoginButton; 
private EditText etxUsername; 
private EditText etxPassword; 
private Button btnLogin; 
private Button btnRegister; 
private Button btnRequestPassword; 
private ImageView backgroundImage; 
private View content; 

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View root = inflater.inflate(R.layout.fragment_login, container, false); 
     fbLoginButton = (LoginButton) root.findViewById(R.id.fb_login); 
     fbLoginButton.setFragment(this); 
     content = root.findViewById(R.id.content); 
     etxUsername = (EditText) root.findViewById(R.id.etx_username); 
     etxPassword = (EditText) root.findViewById(R.id.etx_password); 
     btnLogin = (Button) root.findViewById(R.id.btn_login); 
     btnLogin.setOnClickListener(v -> login()); 
     btnRegister = (Button) root.findViewById(R.id.btn_register); 
     btnRegister.setOnClickListener(v -> showRegister()); 
     btnRequestPassword = (Button) root.findViewById(R.id.btn_request_password); 
     btnRequestPassword.setOnClickListener(v -> requestPassword()); 
     backgroundImage = (ImageView) root.findViewById(R.id.backgroundImage); 
     return root; 
    } 
} 

fragment_login.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

    <ImageView 
     android:id="@+id/backgroundImage" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_centerVertical="true" 
     android:scaleType="centerCrop"/> 

    <ScrollView 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fillViewport="true" 
     android:layout_centerInParent="true" 
     android:background="@color/transparent_black"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="16dp"> 

      <LinearLayout 
       android:id="@+id/login_form" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 

       <ImageView 
        android:layout_width="150dp" 
        android:layout_height="150dp" 
        android:layout_gravity="center" 
        android:layout_marginBottom="@dimen/activity_vertical_margin" 
        android:padding="@dimen/activity_horizontal_margin" 
        android:src="@drawable/login_logo"/> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:minHeight="48dp" 
        android:orientation="horizontal"> 

        <ImageView 
         android:layout_width="24dp" 
         android:layout_height="24dp" 
         android:layout_marginRight="32dp" 
         android:src="@drawable/ic_w_user_24"/> 

        <EditText 
         android:id="@+id/etx_username" 
         style="@style/AccountManagerEditText.Light" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:hint="@string/username_or_email" 
         android:focusable="true" 
         android:nextFocusDown="@+id/etx_password" 
         android:inputType="text"/> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:minHeight="48dp" 
        android:orientation="horizontal"> 

        <ImageView 
         android:layout_width="24dp" 
         android:layout_height="24dp" 
         android:layout_marginRight="32dp" 
         android:src="@drawable/ic_w_password_24"/> 

        <EditText 
         android:id="@+id/etx_password" 
         style="@style/AccountManagerEditText.Light" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:focusable="true" 
         android:hint="@string/password" 
         android:inputType="textPassword"/> 
       </LinearLayout> 
      </LinearLayout> 

      <Button 
       android:id="@+id/btn_request_password" 
       style="@style/VLButtonFlat.Light" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginTop="@dimen/spacing" 
       android:text="@string/forgot_password" 
       android:textAllCaps="false" 
       android:textAppearance="@style/TextAppearance.AppCompat.Caption" 
       android:textColor="@color/white"/> 

      <Button 
       android:id="@+id/btn_login" 
       style="@style/VLButton" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:text="@string/login"/> 


      <TextView 
       style="@style/TextAppearance.AppCompat.Body1" 
       android:layout_width="wrap_content" 
       android:layout_height="38dp" 
       android:autoLink="all" 
       android:clickable="true" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:text="or" 
       android:textColor="@color/white"/> 

      <com.facebook.login.widget.LoginButton 
       android:id="@+id/fb_login" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_marginBottom="@dimen/activity_vertical_margin" 
       android:layout_marginTop="@dimen/activity_vertical_margin"/> 

      <Button 
       android:id="@+id/btn_register" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_weight="1" 
       android:text="@string/create_new_account" 
       android:textAllCaps="false" 
       android:textAppearance="@style/TextAppearance.AppCompat.Caption"/> 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

EDIT: Добавленные стили

<resources 
xmlns:tools=" http://schemas.android.com/tools" 
tools:ignore="MissingPrefix"> 

<style name="AccountManagerTheme.Dark" parent="Theme.AppCompat"> 
    <item name="colorPrimary">@color/black</item> 
    <item name="colorPrimaryDark">@color/black</item> 
    <item name="colorAccent">@color/dirty_white</item> 
    <item name="android:textColorPrimary">@color/black</item> 
    <item name="android:textColorSecondary">@color/dirty_white</item> 
</style> 

<style name="AccountManagerEditText.Light" parent="Base.Widget.AppCompat.EditText"> 
    <item name="android:theme">@style/AccountManagerTheme</item> 
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Body1</item> 
    <item name="android:textColor">@color/white</item> 
    <item name="android:minHeight">48dp</item> 
    <item name="android:textColorHint">@color/dirty_white</item> 
</style> 

<style name="AccountManagerEditText.Dark" parent="Base.Widget.AppCompat.EditText"> 
    <item name="android:theme">@style/AccountManagerTheme.Dark</item> 
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Body1</item> 
    <item name="android:textColorHint">@color/dirty_white</item> 
    <item name="android:minHeight">48dp</item> 
</style> 

+0

силой раскладок на второй 'EditText' –

+0

Можете ли вы опубликовать стили этих edittexts. – Srikanth

+0

@Nilesh, попробовал: 'etxPassword.setOnFocusChangeListener ((v2, HasFocus) -> etxPassword.post (() -> ((InputMethodManager) getActivity() getSystemService (Context.INPUT_METHOD_SERVICE)) .showSoftInput (etxPassword. , InputMethodManager.SHOW_IMPLICIT))); ' и ' etxPassword.setOnClickListener (v1 -> etxPassword.post (() -> ((InputMethodManager) getActivity() getSystemService (Context.INPUT_METHOD_SERVICE)) .showSoftInput. (etxPassword, InputMethodManager.SHOW_IMPLICIT))); ' – iippo

ответ

0

Попробуйте соединить эти два в макете, который является потомком ScrollView: андроид: descendantFocusability = "beforeDescendants" андроид: focusableInTouchMode = "истинный"

Смежные вопросы