Android Studio 屏幕设置

huangapple go评论97阅读模式
英文:

Android Studio screen settings

问题

嗨,大家好,我是 Android Studio 的初学者,
我注意到当我在我的手机上运行我的应用程序时,状态栏和屏幕上的按钮是可见的,但在我朋友的设备上却没有状态栏或屏幕上的按钮,所以它可以使用全屏分辨率,我该如何强制在所有设备上都显示这两者?我手机和他手机的分辨率是相同的(1080x2340),但在他的手机上就像是缩小了一样。
有没有办法让应用在这两种设备上表现一致?我的意思是,分辨率是相同的,但由于状态栏/屏幕上的按钮,应用看起来却不同。

英文:

Hi guys i'm a beginner on android studio,
I noticed that when I run my app on my phone, the status bar and also the on-screen buttons are visible but on my friend's device there is no status bar or on-screen buttons so it uses the full resolution, how can i force the app to have both on all devices? The resolution for my phone and his phone is the same (1080x2340) but on his phone it's like it just zooms out.
Is there a way to set the app to work the same on both devices? I mean, the resolution is the SAME but the app looks different because of status bar/on-screen buttons.

答案1

得分: 1

private void hideSystemUI() {
    // 设置沉浸式标志。
    // 将内容设置为出现在系统栏下方,以便内容在系统栏隐藏和显示时不会调整大小。
    mDecorView.setSystemUiVisibility(
            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 // 隐藏状态栏
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// 此代码段显示系统栏。通过移除除了使内容出现在系统栏下方的标志之外的所有标志来实现。
private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
英文:
private void hideSystemUI() {
    // Set the IMMERSIVE flag.
    // Set the content to appear under the system bars so that the content
    // doesn't resize when the system bars hide and show.
    mDecorView.setSystemUiVisibility(
            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 // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);
}

// This snippet shows the system bars. It does this by removing all the flags
// except for the ones that make the content appear under the system bars.
private void showSystemUI() {
    mDecorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}

huangapple
  • 本文由 发表于 2020年10月1日 21:41:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/64156639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定