Android : Clear Focus On Edittext When Activity Starts
I've some settings page in my app. Once the activity gets starts directly it focus to edittext and i used following code to clear foucs.
Focus another view
Programmatically identify what view you do want to give initial focus to.
@Override
protected void onStart() {
super.onStart();
findViewById( R.id.yourOtherViewId ).requestFocus();
}
Make an earlier view in your layout focusable
If you rather it appears as though "no view has initial focus" you could make the parent view group focusable. In the following example, I make my LinearLayout
focusable by setting android:focusableInTouchMode="true"
:
<LinearLayoutandroid:focusableInTouchMode="true"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"><EditText...
Solution 2:
If Come back from other activity edittext get focused.
put these line onStart() or on onReusme()
RelativeLayoutfocuslayout= (RelativeLayout) findViewById(R.id.RequestFocusLayout);
focuslayout.requestFocus();
Solution 3:
I used the solution shown up in this page but it didn't work. Add this attribute to your activity tag into AndroidManifest:
android:windowSoftInputMode="stateHidden"
It works perfectly.
Solution 4:
Me realy help only android:focusableInTouchMode="true"
in my parent view group.
Solution 5:
Put the code to remove the focus in your onStart() method and it should work fine.
Post a Comment for "Android : Clear Focus On Edittext When Activity Starts"