Android requestFocus detailed explanation and example
Use of requestFocus
In summary in one sentence:
<requestFocus />: The tag is used to specify the focus view within the screen.
The root node of the layout resource file can use container controls (such as LinearLayout, FrameLayout, etc.), or non-container controls (such as EditText, TextView, etc.). For non-container controls, you can only place the <requestFocus /> tag in the non-container control label, indicating that the current control is set to focus. The following code:
<LinearLayout xmlns:andro android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Set incoming ringtone" /> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Set alarm ringtone" /> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Set notification ringtone" /> <EditText android: android:layout_width="match_parent" android:layout_height="wrap_content" > <!-- The current control is in focus --> <requestFocus /> </EditText> </LinearLayout>
In this way, edittext gets focus when entering.
The use of Android requestFocus is finished.
Thank you for reading, I hope it can help you. Thank you for your support for this site!