Android удалить выделение EditText

#android #android-edittext #xamarin.android

#Android #android-edittext #xamarin.android

Вопрос:

введите описание изображения здесь

У меня есть 2 editText секунды, когда я сначала запускаю приложение (оранжевое), текст редактирования выбирается автоматически.

Я попробовал очистить фокус, но у меня это не сработало.

                <LinearLayout
                    style="@style/Widget.CardContent"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@ id/event_title"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textPersonName"
                            android:hint="@string/edit_text_title" />
                    </android.support.design.widget.TextInputLayout>
                    <android.support.design.widget.TextInputLayout
                        android:id="@ id/txtInputLayoutPassword"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@ id/event_description"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textMultiLine"
                            android:hint="@string/edit_text_description" />
                    </android.support.design.widget.TextInputLayout>
                </LinearLayout>
  

Как сделать, чтобы текст первого редактирования выглядел как второй?

Комментарии:

1. Иногда очистки фокуса недостаточно, потому что система (Android) не знает, кому передать фокус. Возьмите родительский макет, LinearLayout и вызывайте requestFocus() в этом представлении после вызова clearFocus() на EditText

Ответ №1:

                    <LinearLayout
                    style="@style/Widget.CardContent"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">


    <!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
                          <LinearLayout
                          android:focusable="true" 
                          android:focusableInTouchMode="true"
                          android:layout_width="0px" 
                          android:layout_height="0px"/>

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@ id/event_title"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textPersonName"
                            android:hint="@string/edit_text_title" />
                    </android.support.design.widget.TextInputLayout>
                    <android.support.design.widget.TextInputLayout
                        android:id="@ id/txtInputLayoutPassword"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <EditText
                            android:id="@ id/event_description"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:inputType="textMultiLine"
                            android:hint="@string/edit_text_description" />
                    </android.support.design.widget.TextInputLayout>
                </LinearLayout>
  

Ответ №2:

Сделайте ViewGroup фокусируемым в сенсорном режиме. Вот так из вашего кода:

    <LinearLayout
   style="@style/Widget.CardContent"
   android:focusableInTouchMode="true"
   android:layout_width="match_parent"
   android:layout_height="wrap_content">
  

Комментарии:

1. Не получается, может быть, это потому, что я использую это в нижней таблице, которую я открывал раньше? Тогда мне понадобится строка кода, чтобы отменить его выбор.