Sdílet prostřednictvím


View.RequestFocus Method

Definition

Overloads

RequestFocus()

Call this to try to give focus to a specific view or to one of its descendants.

RequestFocus(FocusSearchDirection)

Call this to try to give focus to a specific view or to one of its descendants and give it a hint about what direction focus is heading.

RequestFocus(FocusSearchDirection, Rect)

Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from.

RequestFocus()

Call this to try to give focus to a specific view or to one of its descendants.

[Android.Runtime.Register("requestFocus", "()Z", "")]
public bool RequestFocus ();
[<Android.Runtime.Register("requestFocus", "()Z", "")>]
member this.RequestFocus : unit -> bool

Returns

Whether this view or one of its descendants actually took focus.

Attributes

Remarks

Call this to try to give focus to a specific view or to one of its descendants.

A view will not actually take focus if it is not focusable (#isFocusable returns false), or if it can't be focused due to other conditions (not focusable in touch mode (#isFocusableInTouchMode) while the device is in touch mode, not visible, not enabled, or has no size).

See also #focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one.

This is equivalent to calling #requestFocus(int, Rect) with arguments #FOCUS_DOWN and null.

Java documentation for android.view.View.requestFocus().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

RequestFocus(FocusSearchDirection)

Call this to try to give focus to a specific view or to one of its descendants and give it a hint about what direction focus is heading.

[Android.Runtime.Register("requestFocus", "(I)Z", "")]
public bool RequestFocus (Android.Views.FocusSearchDirection direction);
[<Android.Runtime.Register("requestFocus", "(I)Z", "")>]
member this.RequestFocus : Android.Views.FocusSearchDirection -> bool

Parameters

direction
FocusSearchDirection

One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT

Returns

Whether this view or one of its descendants actually took focus.

Attributes

Remarks

Call this to try to give focus to a specific view or to one of its descendants and give it a hint about what direction focus is heading.

A view will not actually take focus if it is not focusable (#isFocusable returns false), or if it is focusable and it is not focusable in touch mode (#isFocusableInTouchMode) while the device is in touch mode.

See also #focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one.

This is equivalent to calling #requestFocus(int, Rect) with null set for the previously focused rectangle.

Java documentation for android.view.View.requestFocus(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

RequestFocus(FocusSearchDirection, Rect)

Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from.

[Android.Runtime.Register("requestFocus", "(ILandroid/graphics/Rect;)Z", "GetRequestFocus_ILandroid_graphics_Rect_Handler")]
public virtual bool RequestFocus (Android.Views.FocusSearchDirection direction, Android.Graphics.Rect? previouslyFocusedRect);
[<Android.Runtime.Register("requestFocus", "(ILandroid/graphics/Rect;)Z", "GetRequestFocus_ILandroid_graphics_Rect_Handler")>]
abstract member RequestFocus : Android.Views.FocusSearchDirection * Android.Graphics.Rect -> bool
override this.RequestFocus : Android.Views.FocusSearchDirection * Android.Graphics.Rect -> bool

Parameters

direction
FocusSearchDirection

One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT

previouslyFocusedRect
Rect

The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint.

Returns

Whether this view or one of its descendants actually took focus.

Attributes

Remarks

Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from. The rectangle can help give larger views a finer grained hint about where focus is coming from, and therefore, where to show selection, or forward focus change internally.

A view will not actually take focus if it is not focusable (#isFocusable returns false), or if it is focusable and it is not focusable in touch mode (#isFocusableInTouchMode) while the device is in touch mode.

A View will not take focus if it is not visible.

A View will not take focus if one of its parents has android.view.ViewGroup#getDescendantFocusability() equal to ViewGroup#FOCUS_BLOCK_DESCENDANTS.

See also #focusSearch(int), which is what you call to say that you have focus, and you want your parent to look for the next one.

You may wish to override this method if your custom View has an internal View that it wishes to forward the request to.

Java documentation for android.view.View.requestFocus(int, android.graphics.Rect).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to