2017-11-02 15 views
1

私はそれをクリックすると、ソフトキーボードが表示されているOKをクリックすると、EditTextを持つフラグメントがあります。 今、私はバックを押すまで何時でもこのキーボードを見えるようにしたいボタン。 現在、EditTextの外側をクリックするたびにキーボードがすぐに隠れるので、私はそれを望んでいません。戻るボタンでソフトキーボードを隠す

マイ・フラグメントXML:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/conversation_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<ListView 
    android:id="@+id/myList" 
    android:layout_width="0dp" 
    android:layout_height="0dp" 
    android:divider="@null" 
    android:paddingBottom="2dp" 
    android:transcriptMode="alwaysScroll" 
    app:layout_constraintBottom_toTopOf="parent" 
    app:layout_constraintEnd_toEndOf="parent" 
    app:layout_constraintStart_toStartOf="parent" 
    app:layout_constraintTop_toBottomOf="parent" 
    tools:layout_editor_absoluteX="0dp" /> 

<LinearLayout 
    android:id="@+id/controlsLayout" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintEnd_toEndOf="parent" 
    app:layout_constraintStart_toStartOf="parent" 
    tools:layout_editor_absoluteX="0dp"> 

     ..... 


      <EditText 
       android:id="@+id/messageInput" 
       android:layout_width="0dp" 
       android:layout_height="44dp" 
       android:inputType="textAutoComplete|textMultiLine" 
       android:paddingEnd="1dp" 
       android:paddingStart="3dp" 
       android:textColor="@android:color/black" /> 

     ..... 


</LinearLayout> 

注:私はボタンを戻るインターセプトする必要はありません。 EditTextをクリックしてもソフト入力キーボードが見えるようにしたい、それだけです。バックボタンが押されたときは、キーボードを非表示にするこれを使用することができます

+0

[ソフトキーボードの戻るボタンをインターセプトする](https://stackoverflow.com/questions/3940127/intercept-back-button-from-soft-keyboard) – Ibrahim

答えて

0

InputMethodManager inputManager = (InputMethodManager) 
            getSystemService(Context.INPUT_METHOD_SERVICE); 

inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 
            InputMethodManager.HIDE_NOT_ALWAYS); 

フォーカスが失われたときにキーボードを隠す機能を無効にするには、私はあなたがあなたのフラグメントにリスナーを追加することができると思います画面上のタッチを処理して何もしません。

View view = inflater.inflate(R.layout.fragment_test, container, false); 

view.setOnTouchListener(new View.OnTouchListener() { 
     public boolean onTouch(View v, MotionEvent event) { 

      // Do nothing 
      return true; 
     } 
}); 

希望すると助かります!

+0

私はフラグメントを使用しています... "OnTouchEvent "フラグメント内に定義されていません – Abuzaid

+0

@Abuzaid申し訳ありません私の悪い! OnTouchListenerを使用できます。私の編集されたポストの例を見つけてください。 – Maxouille

関連する問題