Focus problem summary, Focus Interview Summary

Source: Internet
Author: User

Focus problem summary, Focus Interview Summary

1. If the focus button is used to obtain the focus, it is orange. If edittext is used to obtain the focus, it is a vertical line, and so on. 2. Focus indicates that a touch event may be triggered multiple times, but a click event may be triggered once. Click Event first. In a touch event, if return false, the click event does not exist.


Iii. Focus sequence and switch issues. By default, the focus is obtained from top to bottom by default, but we can also customize the order of focus acquisition to control the mandatory focus acquisition. There are three sentences: get focus btnSearch. setFocusable (true) btnSearch. setFocusableInTouchMode (true); In Touch mode, you need to set focusableInTouchMode to true. BtnSearch. requestFocus ();
SetFocusable (false); certainly, it is not qualified to obtain the focus. So no matter how you do it, there will be no focus, but the touch event and click event are used normally. Only focus is not displayed. 4. Questions about how to get the focus of editext by default, by default, only top-down gets the focus, but edittext has a higher priority to get the focus, even if it is below, it may also obtain the focus first. If you do not allow it to obtain the focus, setfoucable (false) will never be able to obtain the focus qualification, touch or click. So what should I do if I just click or touch to get the focus instead of getting the focus by default? Put an invisible LinearLayout in front of EditText to get the focus first. The Code is as follows: <LinearLayout android: focusable = "true" android: focusableInTouchMode = "true"
Android: nextFocusUp-defines the control that gets the focus when the up key is clicked.

Android: nextFocusDown-defines the control that gets the focus when the down key is clicked.

Android: nextFocusLeft-defines the control that gets the focus when the left key is clicked.

Android: nextFocusRight-defines the control that gets the focus when the right key is clicked.
When a touch event occurs, edittext gets the focus if there is no focus. If setfoucable (false) is set, multiple edittext vertical bars cannot be obtained. If you want to set an EditText file in a form to obtain the focus, you cannot set it, set the focusable before EditText to false.
The editext. clearfocus method is not easy to use.
5. The focus of the pop-up keyboard is irrelevant to the keyboard and the touch event. When a touch event occurs, if editext has no focus, the focus is obtained. When a touch event occurs, the keyboard is displayed. So how can I force a soft keyboard to pop up by default? Use is unrestricted. Even if editext does not have the focus android: windowSoftInputMode = "stateVisible" in the activity attribute of androidmainfest, it will show adjustResize. This Activity always adjusts the screen size so as to leave room for the soft keyboard, this is also very common. The keyboard also pops up.

Meanings of values:

[A] stateUnspecified: the soft keyboard status is not specified. The system selects an appropriate status or depends on the topic settings.

[B] stateUnchanged: When this activity appears, the soft keyboard will remain in the status of the previous activity, whether hidden or displayed.

[C] stateHidden: When you select activity, the keyboard is always hidden.

[D] stateAlwaysHidden: when the Activity's Main Window gets the focus, the keyboard is always hidden.

[E] stateVisible: A soft keyboard is usually visible and displayed as soon as it comes.

[F] stateAlwaysVisible: when the activity is selected, the soft keyboard always displays the status

[G] adjustUnspecified: the default setting. It is usually determined by the system whether to hide or display it.

[H] adjustResize: This Activity always adjusts the screen size to reserve space for the soft keyboard.

[I] adjustPan: the content in the current window will be automatically moved so that the current focus is not overwritten by the keyboard and the user can always see the input content.

"StateUnspecified": The state of the soft keyboard (whether it is hidden or visible) is not specified. the system will choose an appropriate state or rely on the setting in the theme. this is the default setting for the behavior of the soft keyboard. the keyboard status (hidden or visible) is not specified. The system selects an appropriate status or topic-dependent setting. This is the default setting of software disk behavior.
"StateUnchanged": The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore. The soft keyboard remains in the last state.
"StateHidden": The soft keyboard is hidden when the user chooses the activity-that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. when you select this Activity, the keyboard is hidden.
"StateAlwaysHidden": The soft keyboard is always hidden when the activity's main window has input focus. The soft keyboard is always hidden.
"StateVisible": The soft keyboard is visible when that's normally appropriate (when the user is navigating forward to the activity's main window). The keyboard is visible.
"StateAlwaysVisible": The soft keyboard is made visible when the user chooses the activity-that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity. when you select this Activity, the keyboard is visible.
"AdjustUnspecified": It is unspecified whether the activity's main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the currentfocus visible on-screen. the system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. if there is such a view, the window will B E resized, on the assumption that scrolling can make all of the window's contents visible within a smaller area. this is the default setting for the behavior of the main window. it is not specified whether the Activity main window is adjusted to set aside space for the soft keyboard, or whether the content of the window is visible to the current focus on the screen. The system automatically selects one of these modes, depending on whether the content of the window has any layout view that can scroll their content. If there is such a view, the window will be adjusted. This assumption can make the content of the scrolling window visible in a small area. This is the default behavior settings for the main window. That is to say, the system automatically determines whether to adopt the translation mode or the compression mode, and determines whether the content can be rolled.
"AdjustResize": (compression mode) The activity's main window is always resized to make room for the soft keyboard on screen. when a keyboard pops up, adjust the screen size of the main window to reserve space for the keyboard.
"AdjustPan": (translation mode: when the input box is not blocked, the layout is not adjusted in this mode. However, when the input box is to be blocked, the window is translated. That is to say, this mode always keeps the input box visible .) The activity's main window is not resized to make room for the soft keyboard. rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. this is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the windo W. The main window of the Activity does not adjust the screen size to allow space on the keyboard. On the contrary, the content of the current window is automatically moved so that the current focus is not overwritten by the keyboard and the user can always see the part of the input content. This is usually not expected to be adjusted because the user may close the keyboard to obtain interaction with the covered content ..

3. Listen to the show and hide of the Soft Keyboard
Sometimes, using the system's own mechanism to adjust the main window is not the expected result. We may want to manually modify the layout when the keyboard is hidden, in order to make the soft keyboard pop-up more beautiful. In this case, you need to listen to the hidden display of the soft keyboard.
We can use the soft keyboard to display and hide the feature, re-layout the main window to listen. If we set the compression mode, we can track the layout of the onSizeChanged function. If it is in the translation mode, this function may not be called.

How to disable the software keyboard by default?
Method 1:
In AndroidMainfest. xml, select the activity and set the windowSoftInputMode attribute to adjustUnspecified | stateHidden.

Method 2:
Force hide Android Input Method window
For example, EditText edit = (EditText) findViewById (R. id. edit );
InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. hideSoftInputFromWindow (edit. getWindowToken (), 0 );

Method 3 EditText does not bring up the software keyboard (not very useful, you never play it out, what do you do with it)
Example: EditText edit = (EditText) findViewById (R. id. edit );
Edit. setInputType (InputType. TYPE_NULL );



When using the keyboard, you need to consider the following issues:

[1] whether the keyboard is hidden or displayed when a focus is generated

[2] whether to reduce the size of the main activity window to free up space and put it on the keyboard


What can be displayed on the keyboard?: Android: imeOptions = "actionDone" and set it to Done. Clicking Yes will disable the floppy disk.
, Send, search, etc. The default action displayed on the floppy disk is "Next". The Next input box is displayed, as shown in the following figure:


Vi. Focus change monitoring OnWindowFocusChanged ()/*** The onWindowFocusChanged method is used to monitor whether an activity has been loaded. During the Activity lifecycle, * onStart, onResume, and onCreate are not really visible time points, the real visible time point is that the onWindowFocusChanged () function is executed. 7. Example of related classes: setFocusable () sets the view to accept the focus.
IsFocusable () view is qualified to accept focus
SetFocusInTouchMode (): In touch mode, set whether there is a focus to respond to the touch.
IsFocusableInTouchMode () indicates whether the view has the focus qualification in the touch mode.
RequestFocus ()
RequestFocus (int direction) when a user aggregates focus on a certain interface, the parameter is the following four views. FOCUS_LEFT Move focus to the left View. FOCUS_UP Move focus up
View. FOCUS_RIGHT Move focus to the right
View. FOCUS_DOWN Move focus down requestFocusFromTouch () in touch mode
RequestChildFocus (View child, View focused) ------ viewGroup
1. The parent element calls this method.
2 child elements to obtain the focus
3 focused child elements with focus
IsInTouchMode () touch mode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.