Подтвердить что ты не робот

Клавиатура скрывает EditTexts во фрагментах

изменить: Мне нужно использовать клавиатуру, но она скрывает мой EditText, мне нужно ее прокрутить, чтобы клавиатура не скрывала ее.

Я использую планшет Samsung.

Мой стиль:

parent="android:Theme.Holo.NoActionBar.Fullscreen"

Поля EditText находятся в прокручиваемом виде, например:

Макет фрагмента:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_height="match_parent"
         android:layout_width="match_parent"
         android:paddingBottom="@dimen/activity_vertical_margin"
         android:paddingLeft="@dimen/activity_horizontal_margin"
         android:paddingRight="@dimen/activity_horizontal_margin"
         android:paddingTop="@dimen/activity_vertical_margin">

<ScrollView
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_marginBottom="20dp"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/depot_code"/>

        <EditText
            android:hint="@string/enter_depot_code"
            android:id="@+id/etlocationId"
            android:imeOptions="actionNext"
            android:inputType="number"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="12"
            android:singleLine="true">

            <requestFocus/>
        </EditText>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/name"/>

        <EditText
            android:hint="@string/enter_name"
            android:id="@+id/etname"
            android:imeOptions="actionNext"
            android:inputType="textPersonName"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="24"
            android:singleLine="true"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/street"/>

        <EditText
            android:hint="@string/enter_street"
            android:id="@+id/etstreet"
            android:imeOptions="actionNext"
            android:inputType="textPostalAddress"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="24"
            android:singleLine="true"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/suburb"/>

        <EditText
            android:hint="@string/enter_suburb"
            android:id="@+id/etsuburb"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="24"
            android:singleLine="true"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/state"/>

        <Spinner
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:id="@+id/spinner"
            android:imeOptions="actionNext"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="fill_parent"
            android:spinnerMode="dropdown"/>

        <TextView
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/phone"/>

        <EditText
            android:hint="@string/enter_phone"
            android:id="@+id/etphone"
            android:imeOptions="actionDone"
            android:inputType="phone"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:lines="1"
            android:maxLength="12"
            android:singleLine="true"/>

        <Button
            android:id="@+id/btnadd"
            android:layout_gravity="center"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_width="wrap_content"
            android:text="@string/add"/>
    </LinearLayout>
</ScrollView>
</FrameLayout>

Схема действий:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/tech_controller"
          android:layout_height="match_parent"
          android:layout_width="match_parent"
          android:orientation="vertical"
          android:paddingBottom="@dimen/activity_vertical_margin"
          android:paddingLeft="@dimen/activity_horizontal_margin"
          android:paddingRight="@dimen/activity_horizontal_margin"
          android:paddingTop="@dimen/activity_vertical_margin">

< .../ Layouts. ../>

<FrameLayout
    android:id="@+id/second"
    android:layout_height="match_parent"
    android:layout_width="fill_parent"/>
</LinearLayout>

Схожие вопросы были заданы, но я не нашел ответа, который работает.

У меня есть проект, который использует много фрагментов, связанных с одним действием. В моем манифесте для моей деятельности:

android:windowSoftInputMode="stateHidden"

Некоторые фрагменты требуют ввода пользователем.

В макете фрагмента я использую:

Каждый фрагмент вложен следующим образом:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent" .../>

<ScrollView
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <EditText
            android:imeOptions="actionNext"
            or
            android:imeOptions="actionDone" .../>

Это хорошо работает. КРОМЕ клавиатура скрывает EditTexts, которые расположены ниже на странице.

enter image description here

Я читал это снова и снова:

http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions

Пробовал эти предложения, но клавиатура тогда видна, когда вызывается действие, чего я не хочу. Он также не работает. Может быть, потому что это фрагмент?

SoftKeyboard скрывает EditText

Android-клавиатура скрывает EditText

Я пытался разработать динамическое решение. Любая помощь приветствуется.

edit: это для использования на планшетах, и есть только одна опция клавиатуры с изменениями языка.


Изменить: МОЕ РЕШЕНИЕ

Я решил это, установив еще одну мягкую клавиатуру. https://code.google.com/p/softkeyboard/wiki/HowTo

4b9b3361

Ответ 1

Попробуйте вызвать InputMethodManager.hideSoftInputFromWindow() во время функции фрагмента onActivityCreated(), упомянутой в этом SO-ответе?

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    AppUtil.hideKeyboard(getActivity(), getView());
}

где hideKeyboard() выглядит следующим образом

public static void hideKeyboard(Activity activity, View viewToHide) {
    InputMethodManager imm = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(viewToHide.getWindowToken(), 0);
}

Ответ 2

Попробуйте использовать WindowsSoftInputMode только как adjustpan.

Для ex:

android:windowSoftInputMode="adjustPan" 

Ответ 3

Вы можете попробовать поместить это в onActivityCreated вашего фрагмента:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

Это не должно делать клавиатуру при загрузке или запуске вашей активности фрагментом.

Ответ 4

Я решил проблему, установив другую мягкую клавиатуру через магазин воспроизведения Google.

Это были комментарии Питей, которые заставили меня изучить это решение.

Используемый вами IME имеет собственный "плавающий" макет, вы можете попробовать свой код со встроенными IME, такими как Google Keyboard, или настроить IME на нормальный макет полной ширины?

Итак, я понял, что никакая игра с макетом представления не повлияет на мягкую клавиатуру с независимым макетом.

Я использовал эту ссылку https://code.google.com/p/softkeyboard/wiki/HowTo

Он даже работает с Android Manifest:

android:windowSoftInputMode="stateHidden"

Затем я использую imeoptions для управления потоком курсора редактора в представлении.

изменить обновление

Я просто попробовал приложение на не-бренд-планшете Android, в котором есть универсальная клавиатура для Android, и она работает, не меняя ничего. Кажется, клавиатура Samsung по умолчанию болезненна.

Ответ 5

Измените это на LinearLayout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

к

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">

(и закрывающий тег). Обратите внимание на ориентацию.

Обновить манифест Удалить это:

<application ... >
    <activity
      android:windowSoftInputMode="stateVisible|adjustResize|adjustPan">
        ...
    </activity>
    ...
</application>

Изменить это (высота):

<ScrollView
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

Ответ 6

Я пробовал этот код и решал свою проблему.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Ответ 7

имейте в виду, что клавиатура скрытия не работает с getActivity(). getWindow(). setFlags (WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

Ответ 8

Для меня работало ScrollView так же, как и в моем FrameLayout, в котором я добавил это свойство: android: windowSoftInputMode = "adjustPan". В конце он выглядит так и работает. Мне не нужно было ничего менять программно:

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ProductFragment"
    android:windowSoftInputMode="adjustPan">

    <ScrollView
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
      ...
    </ScrollView>
</FrameLayout>