21

edit: I need to use the keyboard, but it hides my EditText, I need it to scroll so the keyboard is not hiding it.

I am using a Samsung tablet.

My style:

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

The EditText fields are in a scrollable view, like so:

The fragment layout:

<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>

The Activity layout:

<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>

Similar questions have been asked, but I have not found an answer that works.

I have a project that uses many fragments attached to the one activity. In my manifest for the activity I have:

android:windowSoftInputMode="stateHidden"

Some of the fragments require user input.

In the fragment layout I use:

Each fragment is nested as follows:

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

This works well. EXCEPT the keyboard hides the EditTexts that are positioned lower on the page.

enter image description here

I have read this over and over:

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

Tried these suggestions, but the keyboard is then visible when the activity is called, which I don't want. It also does not work. Maybe because it is a fragment?

SoftKeyboard hiding EditText

Android Keyboard hides EditText

I have been trying to work out a dynamic solution. Any help is appreciated.

edit: This is for use on tablets and there is only one keyboard option, with language changes.


Edit: MY SOLUTION

I have solved it by installing another soft keyboard. https://code.google.com/p/softkeyboard/wiki/HowTo

Community
  • 1
  • 1
  • can you provide a screenshot? – petey Jul 13 '15 at 21:24
  • 1
    The IME you used has it's own "floating" layout, can you try your code with built-in IMEs like Google Keyboard or set your IME to a normal full-width layout? – Yenchi Jul 13 '15 at 22:04
  • @Heyyou long press on the space bar button in the keyboard. thgis will bring up a dialog that will give you a chooser where you may select another keyboard. – petey Jul 13 '15 at 23:09
  • 1
    @Heyyou try settings > language and input > and look for keyboards – petey Jul 14 '15 at 03:32
  • are you using `getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);` flag or any other flag to full-screen your activity? – Lalit Poptani Jul 14 '15 at 05:19
  • Try clearing flag in `onCreate()` as `getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);` – Lalit Poptani Jul 14 '15 at 08:04

9 Answers9

8

Try to use WindowsSoftInputMode as adjustpan only.

For ex:

android:windowSoftInputMode="adjustPan" 
Vishwa
  • 1,112
  • 1
  • 11
  • 23
5

Try to call InputMethodManager.hideSoftInputFromWindow() during your fragment's onActivityCreated() function mentioned in this SO answer?

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

where hideKeyboard() looks like this

public static void hideKeyboard(Activity activity, View viewToHide) {
    InputMethodManager imm = (InputMethodManager) activity
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(viewToHide.getWindowToken(), 0);
}
Community
  • 1
  • 1
Yenchi
  • 2,076
  • 24
  • 30
4

You can try to put this in onActivityCreated of your fragment:

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

This should not make the keyboard upon loading or starting of your activity with fragment.

Joey
  • 695
  • 6
  • 19
  • Try to add this in your android manifest in addition to my previous answer: `android:windowSoftInputMode="adjustResize"` I think it will work :) – Joey Jul 14 '15 at 05:11
  • 2
    You may try this also `getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);` – Joey Jul 14 '15 at 05:18
  • Hello @Heyyou, just my hunch maybe there's a conflict between scrollview and the soft input keyboard :) Anyway, hope you find the solution. I will get back here when I have my solution again ^_^ – Joey Jul 14 '15 at 09:22
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83179/discussion-between-joey-and-hey-you). – Joey Jul 14 '15 at 09:25
4

I have tried this code and resolve my issue.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Saikat1529
  • 186
  • 12
2

I solved the problem by installing another soft keyboard, via the google play store.

It was Petey's comments that made me explore this solution.

The IME you used has it's own "floating" layout, can you try your code with built-in IMEs like Google Keyboard or set your IME to a normal full-width layout?

So I figured, no amount of playing with the view layout was going to affect a soft keyboard that has an independent layout.

I used this link https://code.google.com/p/softkeyboard/wiki/HowTo

It even works with Android Manifest:

android:windowSoftInputMode="stateHidden"

I then use imeoptions to control the flow of the editor cursor within the view.

edit update

I just tried the app on a no-brand android tablet, which comes with comes with a generic android keyboard and it works, without having to change a thing. It seems the Samsung default keyboard is painful.

Community
  • 1
  • 1
1

Change this to LinearLayout:

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

to

<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">

(and the closing tag). Note the orientation.

Update the manifest Remove this:

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

Change this (height):

<ScrollView
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
xyz
  • 3,349
  • 1
  • 23
  • 29
  • @Heyyou can you add your full xml. I am interested in the parent layouts – xyz Jul 14 '15 at 08:08
  • @Heyyou I tried your XML (with linearlayout) in a new project and it works prefectly. I made one more edit. Try removing that from the mainifest – xyz Jul 14 '15 at 09:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83181/discussion-between-prakharsingh95-and-hey-you). – xyz Jul 14 '15 at 09:42
0

keep in mind that hide keyboard does not work with getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

Terranology
  • 610
  • 9
  • 15
0

Before show your Snackbar widget hide the keyboard like this,

public void showSnackBar(){ 
InputMethodManager manager = (InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
manager.hideSoftInputFromWindow(getView().getWindowToken(),0); 
Snackbar snackbar = Snackbar.make(getView(), "Some message!", Snackbar.LENGTH_INDEFINITE).show(); 
}
Ashana.Jackol
  • 3,064
  • 28
  • 22
-1

What worked for me was using the ScrollView the same way as you in my FrameLayout, in which I added this property: android:windowSoftInputMode="adjustPan". At the end, it looks like this and it is working. I did not need to change anything programatically:

 <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>
camello222
  • 84
  • 5