Java 在横向模式下无法隐藏导航栏
我正在做一个风景模式的游戏。 当我隐藏导航栏时,出现了一个错误 鸟类显示在导航栏上 我在游戏活动中编写了这个代码Java 在横向模式下无法隐藏导航栏,java,android,navigationbar,Java,Android,Navigationbar,我正在做一个风景模式的游戏。 当我隐藏导航栏时,出现了一个错误 鸟类显示在导航栏上 我在游戏活动中编写了这个代码 public class GameActivity extends AppCompatActivity { private GameView gameView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanc
public class GameActivity extends AppCompatActivity {
private GameView gameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
View decorView = getWindow().getDecorView();
int uniOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uniOptions);
Point point = new Point();
getWindowManager().getDefaultDisplay().getSize(point);
gameView = new GameView(this, point.x, point.y);
setContentView(gameView);
}
我把它加在舱单上了
android:screenOrientation="landscape"
当我在肖像上这样做时,效果很好。但我需要这个游戏的横向模式。如何隐藏导航栏而不出错?执行此操作
public void FullScreencall() {
if(Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if(Build.VERSION.SDK_INT >= 19) {
//for new api versions.
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
}
}
public void FullScreencall(){
如果(Build.VERSION.SDK_INT>11&&Build.VERSION.SDK_INT<19){//lower api
视图v=this.getWindow().getDecorView();
v、 设置系统兼容性(View.GONE);
}else if(Build.VERSION.SDK_INT>=19){
//对于新的api版本。
View decorView=getWindow().getDecorView();
int uiOptions=View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.设置系统兼容性(uiOptions);
}
}
如果您希望这是永久性的,只需在onResume()方法中调用FullscreenCall()。我尝试了这段代码,但它不起作用。所以我编辑了我的帖子来展示完整的代码,因为我认为
point
和gameview
有问题,你在用unity吗?不,我没有用。检查此链接并尝试几个答案