Skip to content

Instantly share code, notes, and snippets.

@StelianMorariu
Created July 18, 2019 09:48
Show Gist options
  • Save StelianMorariu/322898b7eaecd5c4a02d36acc3585b86 to your computer and use it in GitHub Desktop.
Save StelianMorariu/322898b7eaecd5c4a02d36acc3585b86 to your computer and use it in GitHub Desktop.
Apply window insets
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// override the default transitions because we create the circular reveal manually
overridePendingTransition(R.anim.anim_no_translate, R.anim.anim_no_translate)
setContentView(R.layout.activity_home)
val rootLayout: FrameLayout = findViewById(R.id.rootLayout)
rootLayout.systemUiVisibility =
SYSTEM_UI_FLAG_LAYOUT_STABLE or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
companion object {
fun newIntent(context: Context): Intent {
return Intent(context, HomeActivity::class.java)
}
}
}
class MetricsProfileFragment : Fragment() {
@Inject
lateinit var viewModelFactory: ViewModelProvider.Factory
lateinit var metricsViewModel: MetricsProfileViewModel
private lateinit var menuBtn: ImageView
private lateinit var loadingImageView: ImageView
private lateinit var titleTv: TextView
private lateinit var motionLayout: MotionLayout
private lateinit var recyclerView: RecyclerView
private lateinit var adapter: MetricsItemAdapter
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_metrics_profile, container, false)
// initialisation code ommitted
return view
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.requestApplyInsets()
view.setOnApplyWindowInsetsListener { view, windowInsets ->
var marginParams = view.layoutParams as ViewGroup.MarginLayoutParams
marginParams.topMargin = windowInsets.systemWindowInsetTop
// marginParams.bottomMargin = windowInsets.systemWindowInsetBottom
windowInsets
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment