如何在Spinner中保持沉浸模式? [英] How do I maintain the Immersive Mode in Spinner?
问题描述
我使用沉浸式粘滞模式隐藏导航栏和操作栏:
I use immersive-sticky mode to hide the navigation bar and action bar:
@TargetApi(19)
private void setImmersiveMode() {
if (Build.VERSION.SDK_INT >= 19) {
View decorView = getWindow().getDecorView();
int uiOptions = getImmersiveUiOptions(decorView);
decorView.setSystemUiVisibility(uiOptions);
ActionBar actionBar = getActionBar();
if (null!=actionBar) {
actionBar.hide();
}
}
}
触摸Spinner
时,将显示navigationBar
并禁用沉浸模式.
When a Spinner
is touched, the navigationBar
is shown and immersive mode is disabled.
此解决方案适用于对话框:
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
dialog.show();
dialog.getWindow().getDecorView().setSystemUiVisibility(
context.getWindow().getDecorView().getSystemUiVisibility());
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
但是Spinner
没有我可以覆盖的show()
方法.
But Spinner
doesn't have show()
method that I could overwrite.
如何防止触摸微调框时显示系统UI?
How can I prevent System UI from showing when a Spinner is touched?
编辑:此问题与隐藏导航栏(BackButton,HomeButton和LatestTasksButton)有关.我已经在使用FLAG_FULLSCREEN
Edit: this question is about keeping the Navigation Bar hidden (BackButton, HomeButton and RecentTasksButton). I'm already using FLAG_FULLSCREEN
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
推荐答案
我知道这已经太晚了,但是我终于找到了解决方法此处:
I know this is super late, but I finally found a solution to this here:
只需在微调器上调用它,然后再使用它:
Just call this on your spinner before using it:
import android.widget.PopupWindow
import android.widget.Spinner
fun Spinner.avoidDropdownFocus() {
try {
val isAppCompat = this is androidx.appcompat.widget.AppCompatSpinner
val spinnerClass = if (isAppCompat) androidx.appcompat.widget.AppCompatSpinner::class.java else Spinner::class.java
val popupWindowClass = if (isAppCompat) androidx.appcompat.widget.ListPopupWindow::class.java else android.widget.ListPopupWindow::class.java
val listPopup = spinnerClass
.getDeclaredField("mPopup")
.apply { isAccessible = true }
.get(this)
if (popupWindowClass.isInstance(listPopup)) {
val popup = popupWindowClass
.getDeclaredField("mPopup")
.apply { isAccessible = true }
.get(listPopup)
if (popup is PopupWindow) {
popup.isFocusable = false
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
这篇关于如何在Spinner中保持沉浸模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!