13

Редактировать: Мне нужно использовать клавиатуру, но она скрывает мой EditText, мне нужно ее прокручивать, чтобы клавиатура не скрывала ее.Клавиатура скрывается Редактирование текста в фрагментах

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

Мой стиль:

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

The 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" .../> 

Это хорошо работает. EXCEPT клавиатура скрывает EditTexts, которые расположены ниже на странице.

enter image description here

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

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

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

SoftKeyboard hiding EditText

Android Keyboard hides EditText

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

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


Edit: МОЕ РЕШЕНИЕ

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

+0

Вы можете предоставить себе снимок экрана? – petey

+0

@petey screenshot добавлен –

+1

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

ответ

3

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

@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); 
} 
+0

Это не работает, на самом деле с помощью 'android: windowSoftInputMode =" adjustPan | adjustResize' в манифесте не работает. –

+0

Хотя это не решило мою проблему, это побудило меня поместить мой метод скрытия клавиатуры в мой класс Utility. Спасибо. –

2

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

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

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

+0

Спасибо, но мне нужно использовать клавиатуру, но она скрывает мой edittext, мне нужно, чтобы она прокручивалась, поэтому клавиатура не скрывает ее. Я обновлю свой Q, чтобы сделать ее более ясной. –

+0

Попробуйте добавить это в свой андроид проявляется в дополнение к моему предыдущему ответу: 'андроида: windowSoftInputMode = "adjustResize"' Я думаю, что это будет работать :) – Joey

+2

Вы можете попробовать это также 'getActivity() GetWindow() setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE..); ' – Joey

1

Изменить это 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"> 

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

Update манифеста Удалить этот:

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

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

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

Спасибо, я пробовал оба из них, без эффекта. –

+0

@Heyyou вы можете добавить свой полный xml. Меня интересуют родительские макеты – prakharsingh95

+0

@prekhar, см. Мое редактирование. –

1

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

Это было Petey's Комментарии, которые заставили меня исследовать это решение.

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

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

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

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

android:windowSoftInputMode="stateHidden" 

я затем использовать imeoptions, чтобы контролировать поток редактора курсора в поле зрения.

редактировать обновление

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

6

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

Для экс:

android:windowSoftInputMode="adjustPan" 
+0

Спасибо, Vishwa, но я пробовал все эти комбинации. –

+0

простой и приятный – aida

-1

То, что сработало для меня использовал Scrollview точно так же, как вы в моем FrameLayout, в котором я добавил это свойство: андроид: 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> 
+0

android: windowSoftInputMode? Это абсолютно неправильно. – TeeTracker

0

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

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); 
Смежные вопросы