Как заставить софт-клавиатуру НЕ скрывать textview / counter под edittext? - PullRequest
2 голосов
/ 02 июня 2019

Проблема в том, что клавиатура Android скрывает просмотр текста под текстом редактирования (не сам текст редактирования!) во время открытия.

Это мой пример макета:

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


    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/big_image"
                android:layout_width="200dp"
                android:layout_height="600dp"
                android:layout_centerHorizontal="true"
                android:background="@color/colorPrimary"
                android:src="@drawable/ic_launcher_foreground"/>


            <android.support.design.widget.TextInputLayout
                android:id="@+id/comment_input_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/big_image">

                <EditText
                    android:id="@+id/comment_edittext_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="your comment"
                    android:imeOptions="actionDone"
                    android:maxLength="250"/>
            </android.support.design.widget.TextInputLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/comment_input_layout"
                android:text="0/250"/>
        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>
</LinearLayout>

Изображения ниже, чтобы прояснить:

экран без клавиатуры

фактическое поведение

ожидаемое поведение

Я нашел несколько похожих вопросов по stackoverflow, ни у одного из них нет решений :( Пожалуйста, помогите мне разобраться с этой проблемой! Убедитесь, что я использовал все советы с учетом android:windowSoftInputMode="adjustPan" или android:windowSoftInputMode="adjustResize" или android:focusableInTouchMode="true" или android:fitsSystemWindows="true" или добавление этого текстового представления отдельно от макета edittext, имеющего framelayout в качестве root,

, но проблема немного сложнее.

Еще одна важная вещь заключается в том, что это текст под текстом редактирования должен

  • оставаться над клавиатурой, пока текст идет по другой строке

  • исчезать при прокрутке текста редактирования (как это часть edittext).

Ответы [ 2 ]

1 голос
/ 18 июня 2019

Вы также можете заархивировать свой дизайн, используя этот дизайн

В XML используется TextInputLayout вместо текста редактирования

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/itFAuthAnswer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/_5sdp"
                    app:passwordToggleEnabled="true"
                    app:counterEnabled="true"// add this 
                    app:counterMaxLength="250" //add this
                    app:hintTextAppearance="@style/AppTextInputHintLabelStyle">

                    <EditText
                        android:id="@+id/etName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="@string/et_auth_f_que_hint"
                        android:imeOptions="actionDone"
                        android:singleLine="true"/>
                </android.support.design.widget.TextInputLayout>

Эта строка кода решает вашу проблему по-другому и также подходит для вашего дизайна смородины.

app:counterEnabled="true"// make it true
app:counterMaxLength="250"//set your limit

Счастливого обучения ...

0 голосов
/ 02 июня 2019

пожалуйста, добавьте это app:counterEnabled="true "app:counterMaxLength="250" к вашему TextInputLayout

<android.support.design.widget.TextInputLayout
         android:id="@+id/comment_input_layout"
         android:layout_width="match_parent"
         app:counterEnabled="true"
         app:counterMaxLength="250"
         android:layout_height="wrap_content"
         android:layout_below="@+id/big_image">
   <EditText
      android:id="@+id/comment_edittext_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="your comment"
      android:imeOptions="actionDone"
      android:maxLength="250"/> 

Редактировать:

пожалуйста, попробуйте сэто в вашем манифесте

android:windowSoftInputMode="stateVisible|adjustResize"
...