2017-11-02 19 views
1

편집 텍스 트가있는 조각이 있는데, 클릭하면 소프트 키보드가 나타납니다. 이제 뒤로를 누를 때까지이 키보드를 계속 볼 수 있습니다. 단추. 현재 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