我使用沉浸式粘性模式来隐藏导航栏和操作栏:
@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
并禁用沉浸式模式。
This solution适用于Dialogs:
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()
方法。
如何在触摸微调器时阻止系统UI显示?
编辑:这个问题是关于隐藏导航栏(BackButton,HomeButton和RecentTasksButton)。我已经在使用FLAG_FULLSCREEN
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
答案 0 :(得分:2)
答案 1 :(得分:1)
对于像我一样,将开始将@Quinn粘贴的解决方案从Kotlin重写到Java的每个人,后来他们发现the linked git repo也是Java的解决方案,我将其粘贴在这里:>
import android.widget.ListPopupWindow;
import android.widget.PopupWindow;
import android.widget.Spinner;
public static void avoidSpinnerDropdownFocus(Spinner spinner) {
try {
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);
}
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}