2017-10-25 8 views
0

私のアプリの断片の1つにedittextがあり、それをクリックするたびにキーボードが現れ、断片の中のすべてのコンテンツがedittextを含めて消えます。私はまだキーボードに入力することができます、そして、私が戻るボタンを押した後、すべてが戻って、私が入力したものが編集テキストに表示されますが、すべてを消してしまうのを止めるには?Android EditTextキーボードの断片化が消える

以下は、フラグメントとそのレイアウトのコードです。

フラグメント:

import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

public class PaymentsFragment extends Fragment { 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
     // Inflate the layout for this fragment 
     return inflater.inflate(R.layout.fragment_payments, container, false); 
    } 
} 

レイアウト:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 

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

<EditText 
    android:id="@+id/editText2" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 

    android:hint="Enter Something" 

    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintRight_toLeftOf="@+id/button2" 

    android:layout_marginLeft="16dp" 
    android:layout_marginTop="16dp" 
    android:layout_marginRight="16dp" /> 

<Button 
    android:id="@+id/button2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:text="Button" 

    app:layout_constraintBaseline_toBaselineOf="@+id/editText2" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintLeft_toRightOf="@+id/editText2" 

    android:layout_marginLeft="0dp" 
    android:layout_marginRight="16dp" /> 

</android.support.constraint.ConstraintLayout> 

答えて

1

参考:Developer documentation

アンドロイド:windowSoftInputMode

ウィンドウの一部がソフトキーボードで覆われているときに、現在のフォーカスを表示させるためにコンテンツのパンが表示されているかどうかを、アクティビティのメインウィンドウに加えます。

活動のメインウィンドウが常に画面上のソフトキーボード のための余地を作るためにリサイズされ

adjustResize。

adjustPan

活動のメインウィンドウは、ソフト キーボードのための余地を作るためにリサイズされていません。むしろ、ウィンドウの内容は自動的に のようにパンされ、現在のフォーカスがキーボードによって隠されることはなく、ユーザは入力中のものを常に見ることができます。 ユーザがソフトキーボードを閉じて に移動して、ウィンドウの不明瞭な部分と対話する必要がある場合があるため、これは一般的には、 のサイズ変更よりも望ましくありません。

マニフェストにこの方法を使用します。

<activity android:windowSoftInputMode="adjustResize"> </activity> 
関連する問題