2016-05-04 14 views
0

私は多くのEditTextを持っていますが、ボタンをクリックするとすべてからフォーカスが取り消されますが、最初のEditTextがハイライト表示され、私は、すべての初期条件EditExt XMLでクリックしたときにハイライトのEditTextを削除する方法

private void buttonClick(){ 

    mTxtFld2.setCursorVisible(false); 
    mTxtFld3.setCursorVisible(false); 
    mTxtFld4.setCursorVisible(false); 
    mTxtFld5.setCursorVisible(false); 

    mTxtFld2.clearFocus(); 
    mTxtFld3.clearFocus(); 
    mTxtFld4.clearFocus(); 
    mTxtFld5.clearFocus(); 

    mTxtFld2.setSelectAllOnFocus(false); 
    mTxtFld3.setSelectAllOnFocus(false); 
    mTxtFld4.setSelectAllOnFocus(false); 
    mTxtFld5.setSelectAllOnFocus(false); 

    mTxtFld2.setBackgroundColor(Color.TRANSPARENT); 
    mTxtFld3.setBackgroundColor(Color.TRANSPARENT); 
    mTxtFld4.setBackgroundColor(Color.TRANSPARENT); 
    mTxtFld5.setBackgroundColor(Color.TRANSPARENT); 

    View v = getActivity().getCurrentFocus(); 
    if (v == null) return; 

    InputMethodManager imm = (InputMethodManager) 
      getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 
} 

をリセットしたい

<EditText 
      android:layout_width="621dp" 
      android:layout_height="44dp" 
      android:layout_marginTop="10dp" 
      android:layout_marginLeft="21dp" 
      android:id="@+id/EditText2" 
      android:inputType="textNoSuggestions" 
      android:fontFamily="fonts/Montserrat-Bold.ttf" 
      android:selectAllOnFocus="true" 
      android:gravity="center" 
      android:singleLine="true" 
      android:focusable="true" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" 
      android:hint="@string/name" 
      android:textColorHint="@color/text_placeholder" 
      android:background="@drawable/back" /> 
+0

キーボードを隠すことで、すべての入力フォーカスをリセットできます。getWindow()。setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN ); –

答えて

1

あなたはにフォーカスを設定するために隠されたフォーカス可能なレイアウトを使用することができます:あなたのoffButtonアクションで

<LinearLayout 
    android:id="@+id/dummy_focus" 
    android:layout_width="0px" 
    android:layout_height="0px" 
    android:focusable="true" 
    android:focusableInTouchMode="true" /> 

、このレイアウトに焦点を合わせます。

関連する問題