Alessandro Roaro
Alessandro Roaro

Reputation: 4733

manage the focus in a custom view

I am implementing a custom View and I want to manage the focus so that when it's in the focused state it is drawed in a different way than in the normal state. I know that I probably have to override onFocusChanged, but how do I get that method called when the view should lose the focus, for example when there is a tap outside of it? I have searched in the docs but with no luck.

Upvotes: 4

Views: 2440

Answers (1)

Carlos EduardoL
Carlos EduardoL

Reputation: 670

The method onFOcusChanged is called every time that the focus of your view is changed, so, if the user tap outside your view you will receive a call in onFocusChanged.

The first parameter show if you gain the focus or lose it.

protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {}

Upvotes: 1

Related Questions