当按下微调器下拉时,全屏模式被禁用
when pressed the spinner drop down, full screen mode disabled
我正在为一个 android 项目使用 Java,因为我必须在全屏模式下使用该应用程序,当我按下下拉菜单(微调器)时,全屏模式被禁用.您有什么选择可以防止这种情况发生吗?即使我按下下拉,我也不想退出全屏。
我已经完成了所有选项,包括
//method for full screen
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Main_Menu.this,
R.layout.custom_spinner, paths);
adapter.setDropDownViewResource(R.layout.custom_spinner_drop_down_item);
btnlanguage.setAdapter(adapter);
btnlanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// Toast.makeText(Main_Menu.this, urlinformation.HomeURL(btnlanguage.getSelectedItem().toString(), slug), Toast.LENGTH_LONG).show();
mywebview.loadUrl(urlinformation.HomeURL(btnlanguage.getSelectedItem().toString(), slug));
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
这里是解决方法,把这个方法放在你的代码中,并在向微调器添加数据后调用onCreate方法。
public static void apply(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();
}
}
Appcompact 微调器更新 Java。确保导入正确才能正常工作
public static void avoidSpinnerDropdownFocus(AppCompatSpinner spinner) {
try {
if(spinner instanceof AppCompatSpinner){
Field listPopupField = AppCompatSpinner.class.getDeclaredField("mPopup");
listPopupField.setAccessible(true);
Object listPopup = listPopupField.get(spinner);
if (listPopup instanceof androidx.appcompat.widget.ListPopupWindow) {
Field popupField = androidx.appcompat.widget.ListPopupWindow.class.getDeclaredField("mPopup");
popupField.setAccessible(true);
Object popup = popupField.get(listPopup);
if (popup instanceof PopupWindow) {
((PopupWindow) popup).setFocusable(false);
}
}
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
我正在为一个 android 项目使用 Java,因为我必须在全屏模式下使用该应用程序,当我按下下拉菜单(微调器)时,全屏模式被禁用.您有什么选择可以防止这种情况发生吗?即使我按下下拉,我也不想退出全屏。 我已经完成了所有选项,包括
//method for full screen
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Main_Menu.this,
R.layout.custom_spinner, paths);
adapter.setDropDownViewResource(R.layout.custom_spinner_drop_down_item);
btnlanguage.setAdapter(adapter);
btnlanguage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
// Toast.makeText(Main_Menu.this, urlinformation.HomeURL(btnlanguage.getSelectedItem().toString(), slug), Toast.LENGTH_LONG).show();
mywebview.loadUrl(urlinformation.HomeURL(btnlanguage.getSelectedItem().toString(), slug));
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
这里是解决方法,把这个方法放在你的代码中,并在向微调器添加数据后调用onCreate方法。
public static void apply(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();
}
}
Appcompact 微调器更新 Java。确保导入正确才能正常工作
public static void avoidSpinnerDropdownFocus(AppCompatSpinner spinner) {
try {
if(spinner instanceof AppCompatSpinner){
Field listPopupField = AppCompatSpinner.class.getDeclaredField("mPopup");
listPopupField.setAccessible(true);
Object listPopup = listPopupField.get(spinner);
if (listPopup instanceof androidx.appcompat.widget.ListPopupWindow) {
Field popupField = androidx.appcompat.widget.ListPopupWindow.class.getDeclaredField("mPopup");
popupField.setAccessible(true);
Object popup = popupField.get(listPopup);
if (popup instanceof PopupWindow) {
((PopupWindow) popup).setFocusable(false);
}
}
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}