我正在尝试以全屏(沉浸式模式)打开下拉式微调器,但问题是当下拉式打开时它会在底部显示半透明导航栏。选择选项时,导航栏会隐藏,但只要下拉列表可见,导航栏就会保持可见状态。
我能够在对话框片段中删除此行为,因为我有show(FragmentManager manager, String tag)
方法来覆盖并添加此
getDialog().getWindow().getDecorView().setSystemUiVisibility(getActivity()
.getWindow().getDecorView().getSystemUiVisibility());
// Make the dialogs window focusable
again.getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
但没有类似于旋转器中可用的方法。我尝试将这些方法放在performClick()
中使用父级中的侦听器实现,但仍然没有运气。
此问题的任何解决方案。
答案 0 :(得分:0)
试试这段代码:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
答案 1 :(得分:0)
为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();
}
}
供Kotlin用户使用此扩展功能
import android.widget.ListPopupWindow
import android.widget.PopupWindow
import android.widget.Spinner
fun Spinner.avoidDropdownFocus() {
try {
val listPopup = Spinner::class.java
.getDeclaredField("mPopup")
.apply { isAccessible = true }
.get(this)
if (listPopup is ListPopupWindow) {
val popup = ListPopupWindow::class.java
.getDeclaredField("mPopup")
.apply { isAccessible = true }
.get(listPopup)
if (popup is PopupWindow) {
popup.isFocusable = false
}
}
} catch (e: Exception) {
e.printStackTrace()
}
}
您需要在spinner
方法中或在OnCreate
膨胀时或使用之前的任何时间从Spinner
调用该方法。
spinner.avoidSpinnerDropdownFocus()
kakajika GitHub用户kakajika的积分 https://gist.github.com/kakajika/a236ba721a5c0ad3c1446e16a7423a63