Stay organized with collections
Save and categorize content based on your preferences.
OnWindowFocusChangeListener
interface OnWindowFocusChangeListener
Interface definition for a callback to be invoked when the view hierarchy's window focus state changes.
Summary
Public methods |
abstract Unit |
Callback method to be invoked when the window focus changes in the view tree.
|
Public methods
onWindowFocusChanged
abstract fun onWindowFocusChanged(hasFocus: Boolean): Unit
Callback method to be invoked when the window focus changes in the view tree.
Parameters |
hasFocus |
Boolean: Set to true if the window is gaining focus, false if it is losing focus. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# ViewTreeObserver.OnWindowFocusChangeListener\n\nAdded in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nOnWindowFocusChangeListener\n===========================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/view/ViewTreeObserver.OnWindowFocusChangeListener \"View this page in Java\") \n\n```\ninterface OnWindowFocusChangeListener\n```\n\n|----------------------------------------------------------------|\n| [android.view.ViewTreeObserver.OnWindowFocusChangeListener](#) |\n\nInterface definition for a callback to be invoked when the view hierarchy's window focus state changes.\n\nSummary\n-------\n\n| Public methods ||\n|---------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [onWindowFocusChanged](#onWindowFocusChanged(kotlin.Boolean))`(`hasFocus:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Callback method to be invoked when the window focus changes in the view tree. |\n\nPublic methods\n--------------\n\n### onWindowFocusChanged\n\nAdded in [API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nabstract fun onWindowFocusChanged(hasFocus: Boolean): Unit\n```\n\nCallback method to be invoked when the window focus changes in the view tree.\n\n| Parameters ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `hasFocus` | [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html): Set to true if the window is gaining focus, false if it is losing focus. |"]]