I am trying to replicate, in java, the following code written in Kotlin. It practically set the layout in fullscreen following some logic, in particular the binding takes place on the element CoordinatorLayout
through app:layoutFullscreen="@{true}"
.
@BindingAdapter("layoutFullscreen")
fun View.bindLayoutFullscreen(previousFullscreen: Boolean, fullscreen: Boolean) {
if (previousFullscreen != fullscreen && fullscreen) {
systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
}
I tried to turn everything into java but I have various errors
@BindingAdapter("layoutFullscreen")
public static void bindLayoutFullscreen(Boolean previousFullscreen, Boolean fullscreen) {
if (previousFullscreen != fullscreen && fullscreen) {
View.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
}
}
How can I get the same functioning of the kotlin code in java?
Thanks in advance, Giacomo.
Notice that:
view
is the first parameter.or
is |
in java.systemUiVisibility
used on the view
;
in java end of line is a must.Here is the working java version:
@BindingAdapter("layoutFullscreen")
public static void bindLayoutFullscreen(View view, boolean previousFullscreen, boolean fullscreen) {
if (previousFullscreen != fullscreen && fullscreen) {
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
}
}