Android Spinner:如何在全屏状态下隐藏状态栏?
我使用此代码来隐藏导航栏:
View root = findViewById(android.R.id.content);
root.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
但是当触摸微调器时,状态栏会显示在屏幕顶部。
此解决方案似乎在 android:spinnerMode="dropdown"
时有效
Field listPopupField = Spinner.class.getDeclaredField("mPopup");
listPopupField.setAccessible(true);
Object listPopup = listPopupField.get(spinner);
if (listPopup instanceof ListPopupWindow) {
Field popupField = ListPopupWindow.class.getDeclaredField("mPopup");
popupField.setAccessible(true);
Object popup = popupField.get((ListPopupWindow) listPopup);
if (popup instanceof PopupWindow) {
((PopupWindow) popup).setFocusable(false);
}
}
android:spinnerMode="dialog"
有解决方案吗?
I use this code to to hide the navigation bar:
View root = findViewById(android.R.id.content);
root.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
But when a Spinner is touched, the status bar is shown on top of the screen.
This solution seems to work when android:spinnerMode="dropdown"
Field listPopupField = Spinner.class.getDeclaredField("mPopup");
listPopupField.setAccessible(true);
Object listPopup = listPopupField.get(spinner);
if (listPopup instanceof ListPopupWindow) {
Field popupField = ListPopupWindow.class.getDeclaredField("mPopup");
popupField.setAccessible(true);
Object popup = popupField.get((ListPopupWindow) listPopup);
if (popup instanceof PopupWindow) {
((PopupWindow) popup).setFocusable(false);
}
}
Is there a solution for android:spinnerMode="dialog"
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当重新创建弹出窗口时,每次单击微调器时都需要清除焦点;但不幸的是没有直接的 API 来监听这个事件。
为了克服这个问题,您可以创建一个自定义 Spinner &重写其
performClick()
,当单击微调器以显示菜单时会触发该函数。然后您就可以在分享时清除焦点。You need to clear the focus every time you click the spinner as the popupWindow is recreated; but unfortunately there is no direct API for listening to this event.
To overcome this you can create a custom Spinner & override its
performClick()
which gets triggered when the spinner is clicked to show up the menu. Then you can clear the focus as you shared.