Java 按下微调器下拉按钮时,全屏模式被禁用
我将Java用于android项目,因为我必须在全屏模式下使用应用程序,当我按下下拉菜单(微调器)时,全屏模式被禁用。你有什么办法来防止这种情况吗?即使我按下下拉键,我也不想退出全屏。 我已经考虑了所有的选择,包括Java 按下微调器下拉按钮时,全屏模式被禁用,java,android,android-spinner,Java,Android,Android Spinner,我将Java用于android项目,因为我必须在全屏模式下使用应用程序,当我按下下拉菜单(微调器)时,全屏模式被禁用。你有什么办法来防止这种情况吗?即使我按下下拉键,我也不想退出全屏。 我已经考虑了所有的选择,包括 //method for full screen private void hideSystemUI() { View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(
//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) {
}
});
//全屏显示的方法
私有void hideSystemUI(){
View decorView=getWindow().getDecorView();
decorView.setsystemivilibility(
View.SYSTEM\u UI\u FLAG\u沉浸式
|View.SYSTEM\u UI\u FLAG\u布局\u稳定
|View.SYSTEM\u UI\u FLAG\u布局\u隐藏\u导航
|View.SYSTEM\u UI\u FLAG\u布局\u全屏显示
|View.SYSTEM\u UI\u FLAG\u HIDE\u导航
|视图。系统(用户界面、标志、全屏);
}
ArrayAdapter=新的ArrayAdapter(主菜单,
R.layout.custom_微调器,路径);
adapter.setDropDownViewResource(R.layout.custom\u微调器\u下拉项);
btnlanguage.setAdapter(适配器);
btnlanguage.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图selectedItemView、整型位置、长id){
//Toast.makeText(主菜单.this,urlinformation.HomeURL(btnlanguage.getSelectedItem().toString(),slug),Toast.LENGTH\u LONG.show();
mywebview.loadUrl(urlinformation.HomeURL(btnlanguage.getSelectedItem().toString(),slug));
}
@凌驾
未选择公共无效(AdapterView父视图){
}
});
这是解决方案,将此方法放入代码中,并在向spinner添加数据后调用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();
}
}