web-dev-qa-db-fra.com

Cacher le clavier EditTexts en fragments

edit: Je dois utiliser le clavier, mais il cache ma EditText, il me faut du défilement pour que le clavier ne le cache pas.  

J'utilise une tablette Samsung.

Mon style:

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

Les champs EditText sont dans une vue déroulante, comme suit: 

La disposition des fragments:

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

La mise en page de l'activité:

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

Des questions similaires ont été posées, mais je n’ai trouvé aucune réponse satisfaisante.

J'ai un projet qui utilise plusieurs fragments attachés à une activité. Dans mon manifeste pour l'activité que j'ai:

Android:windowSoftInputMode="stateHidden"

Certains fragments nécessitent une intervention de l'utilisateur.

Dans la disposition des fragments, j'utilise:

Chaque fragment est imbriqué comme suit:

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

Ça marche bien. SAUF Le clavier masque les EditTexts qui sont positionnés plus bas sur la page.

enter image description here

J'ai lu ceci à plusieurs reprises:

http://developer.Android.com/reference/Android/widget/TextView.html#attr_Android:imeOptions

J'ai essayé ces suggestions, mais le clavier est alors visible lorsque l'activité est appelée, ce que je ne veux pas. Cela ne marche pas non plus. Peut-être parce que c'est un fragment?

SoftKeyboard masquant EditText

Le clavier Android cache EditText

J'ai essayé de trouver une solution dynamique. Toute aide est appréciée.

edit: Ceci est destiné aux tablettes. Il n’ya qu’une option de clavier, avec changement de langue.


Modifier: MA SOLUTION

Je l'ai résolu en installant un autre clavier logiciel. https://code.google.com/p/softkeyboard/wiki/HowTo

14
Yvette Colomb

Essayez d'appeler InputMethodManager.hideSoftInputFromWindow() pendant la fonction onActivityCreated() de votre fragment mentionnée dans ce SO answer ?

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

hideKeyboard() ressemble à ceci

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

Essayez d’utiliser WindowsSoftInputMode comme adjustpan uniquement.

Pour ex:

Android:windowSoftInputMode="adjustPan" 
7
Vishwa

Vous pouvez essayer de mettre ceci dans onActivityCreated de votre fragment: 

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

Cela ne devrait pas rendre le clavier lors du chargement ou du démarrage de votre activité avec fragment.

2
Joey

J'ai résolu le problème en installant un autre clavier logiciel, via le Google Play Store.

Ce sont _ { Petey) commentaires qui m'ont poussé à explorer cette solution.

L'IME que vous avez utilisé a sa propre disposition "flottante". Pouvez-vous essayer votre code avec des IME intégrés tels que Google Keyboard ou définir votre IME sur une présentation pleine largeur normale?

J'ai donc pensé que jouer avec la disposition de la vue n'affecterait pas un clavier logiciel doté d'une disposition indépendante.

J'ai utilisé ce lien https://code.google.com/p/softkeyboard/wiki/HowTo } _

Cela fonctionne même avec Android Manifest:

Android:windowSoftInputMode="stateHidden"

J'utilise ensuite imeoptions pour contrôler le flux du curseur de l'éditeur dans la vue.

edit update

Je viens d'essayer l'application sur une tablette Android sans marque, livrée avec un clavier générique Android, et cela fonctionne, sans rien changer. Il semble que le clavier par défaut de Samsung est douloureux.

2
Yvette Colomb

J'ai essayé ce code et résolu mon problème.

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

Changez ceci en 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">

(et la balise de fermeture). Notez l'orientation.

Mettre à jour le manifeste Supprimer ceci :

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

Change ceci (hauteur) :

<ScrollView
    Android:layout_height="wrap_content"
    Android:layout_width="match_parent">
1
ps95