If you have edittext in the page, you will get the focus by default, and if you do not want to get the focus when you enter the page, follow these steps:
1. Add properties to the outermost layer of the layout:
Android:focusable= "true"
Android:focusableintouchmode= "true"
2. Add a tag to the outermost layout:
<requestfocus/>
The effect is:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:focusable= "true"
Android:focusableintouchmode= "true" >
<requestfocus/>
<edittext
Android:id= "@+id/et_content"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"/>
</RelativeLayout>
If you also want to lose focus when you click outside of EditText, you can add a click event to the layout:
Contentview.setontouchlistener (New Ontouchlistener () {
@Override
public boolean OnTouch (View V, motionevent event) {
if (event.getaction () = = Motionevent.action_down) {
Et_content.clearfocus ();
}
return false;
}
});
Contentview on the top of that layout file.
View Contentview = View.inflate (Getapplicationcontext (), r.layout.activity_xx, NULL);
Et_content is your edittext.
Android cancels EditText focus