Last active
May 25, 2018 09:48
-
-
Save wbinarytree/57f0caf30fe68c897ebdc5da781bc8df to your computer and use it in GitHub Desktop.
FitsystemWindow with FrameLayout!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.airweb.waw.wawmusicplayer.ui.widgets | |
| import android.content.Context | |
| import android.support.v4.view.ViewCompat | |
| import android.support.v4.view.WindowInsetsCompat | |
| import android.util.AttributeSet | |
| import android.view.View | |
| import android.view.ViewGroup | |
| import android.widget.FrameLayout | |
| /** | |
| * Use for fragment that make [FrameLayout] can be system awared. by their children. | |
| * @see <https://stackoverflow.com/a/47349880/3979479> | |
| */ | |
| class FitWindowFrameLayout : FrameLayout { | |
| constructor(context: Context) : this(context, null) | |
| constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0) | |
| constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, | |
| attrs, | |
| defStyleAttr) { | |
| setOnHierarchyChangeListener(object : ViewGroup.OnHierarchyChangeListener { | |
| override fun onChildViewAdded(parent: View, child: View) { | |
| ViewCompat.requestApplyInsets(this@FitWindowFrameLayout) | |
| } | |
| override fun onChildViewRemoved(parent: View, child: View) { | |
| ViewCompat.requestApplyInsets(this@FitWindowFrameLayout) | |
| } | |
| }) | |
| ViewCompat.setOnApplyWindowInsetsListener(this) { v, insets -> | |
| val childCount = childCount | |
| for (index in 0 until childCount) { | |
| ViewCompat.dispatchApplyWindowInsets(getChildAt(index), WindowInsetsCompat(insets)) | |
| } | |
| return@setOnApplyWindowInsetsListener insets | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment