121

我提到了这个链接。如果用户点击 EditText(例如 To: ),那么键盘将被弹出,同时用户可以滚动查看所有剩余的视图(例如:撰写、主题、发送按钮)那个屏幕。同样,在我的应用程序中,我有一项活动,即我有一些小部件或视图。假设如果用户单击我的 Activity 中的 Edittext,那么键盘会弹出,我可以滚动查看剩余的视图。但是如果我android:theme="@android:style/Theme.NoTitleBar.Fullscreen"在清单中给出这个属性我无法滚动查看剩余的视图但是如果给出属性android:theme="@android:style/Theme.NoTitleBar"像这样在清单中我可以滚动查看剩余视图但该屏幕中有状态栏,这里我想要全屏,即使弹出键盘我也可以滚动查看剩余视图..?我必须为此做出哪些改变..?

4

34 回答 34

189

写在你的活动中

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

在此处查看文档:https ://developer.android.com/training/system-ui/status.html

你的应用程序将全屏显示。没有状态栏,没有标题栏。:)

于 2011-03-25T18:11:25.583 回答
21

使用主题"Theme.NoTitleBar.Fullscreen"并尝试设置"android:windowSoftInputMode=adjustResize"活动,您可以在此处AndroidManifest.xml.找到详细信息。

于 2011-03-25T11:14:56.343 回答
20

使用此代码在您的应用中隐藏状态栏并易于使用

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
于 2019-01-14T13:09:03.990 回答
19
 if (Build.VERSION.SDK_INT < 16) {
   getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
 } else {
     View decorView = getWindow().getDecorView();
      int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
      decorView.setSystemUiVisibility(uiOptions);
      ActionBar actionBar = getActionBar();
      actionBar.hide();
 }
于 2014-05-10T00:23:51.390 回答
14

如果您在一项活动中需要此功能,则必须在 setContentView 之前放入 onCreate:

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.your_screen);
于 2016-02-12T09:40:58.250 回答
12

将此添加到您的活动类

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow().setFlags(
                        WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);
    // some your code
}
于 2017-06-22T07:15:08.823 回答
9

将此用于您的Activity.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
于 2016-04-04T13:40:15.023 回答
8

如果您要隐藏状态栏,请在 onCreate(for Activity) 和 onCreateView/onViewCreated(for Fragment) 中执行此操作

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

并且不要忘记在退出活动时清除标志,否则访问此活动后您的整个应用程序将全屏显示。要清除在 onDestroy(for Activity) 或 onDestroyView(for Fragment) 中执行此操作

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
于 2020-02-07T11:05:31.343 回答
6

更改manifest.xml文件中应用程序的主题。

android:theme="@android:style/Theme.Translucent.NoTitleBar"
于 2014-07-12T06:31:46.030 回答
6
void hideStatusBar() {
        if (Build.VERSION.SDK_INT < 16) {
           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            View decorView = getWindow().getDecorView();
            int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
            decorView.setSystemUiVisibility(uiOptions);
        }
    }

您可以使用此方法隐藏状态栏。这对于隐藏操作栏也很重要。在这种情况下,如果您从支持库(如 Appcompat)扩展了活动,则可以getSupportActionBar().hide(),或者您可以在上述方法之后简单地调用getActionBar().hide() 。谢谢

于 2017-02-03T01:01:16.710 回答
5

在 AndroidManifest.xml -> 要使用的活动内,添加以下内容:

android:theme="@style/Theme.AppCompat.Light.NoActionBar"
//this is for hiding action bar

并在 MainActivity.java -> onCreate() 方法内,添加以下内容:

this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//this is for hiding status bar
于 2018-04-19T10:38:05.673 回答
5

使用此代码:

requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.youractivityxmlname);
于 2016-05-06T06:50:13.487 回答
4

由于 FLAG_FULLSCREEN 已从 android R 中弃用。您可以使用以下代码隐藏状态栏。

 @Suppress("DEPRECATION")
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {

           window.insetsController?.hide(WindowInsets.Type.statusBars())
    } else {

           window.setFlags(
                    WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN
            )
        }
于 2020-09-25T22:59:59.020 回答
4

您可以使用 styles.xml 隐藏

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>
<style name="HiddenTitleTheme" parent="AppTheme">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
</style>

像这样在你的清单中调用它android:theme="@style/HiddenTitleTheme"

于 2018-07-20T06:35:12.357 回答
4

此代码隐藏状态栏。

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

隐藏操作栏写下这一行: -

requestWindowFeature(Window.FEATURE_NO_TITLE);

这两行可以一起写来隐藏操作栏和状态栏。所有这些行都必须在setContentView方法中的方法调用之前编写onCreate

于 2016-11-11T11:47:29.840 回答
3

这对我来说是最好的解决方案,只需在你的 theme.xml 中写下这一行

<style name="MyApp" parent="Theme.AppCompat.Light.NoActionBar">
...
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
...
</style>
于 2021-05-26T09:08:31.863 回答
3

您可以通过使用xml将其颜色设置为 transperant 来隐藏状态栏。将statusBarColor项目添加到您的活动主题中:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>
于 2019-01-07T18:34:23.577 回答
2
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme(R.style.Theme_AppCompat_Light_NoActionBar);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
    , WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity__splash_screen);
}
于 2019-11-10T21:48:30.940 回答
1

如果您正在使用更高的 API,那么您可能已经注意到上述答案中提到的标志,FLAG_FULLSCREEN即已SYSTEM_UI_FLAG_FULLSCREEN弃用。

要覆盖整个屏幕,您可以定义自定义主题:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="ActivityTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowFullscreen">true</item>
    </style>
</resources>

在你的活动中添加主题,你就完成了。manifestandroid:theme="@style/ActivityTheme"

注意:您也可以直接在清单中添加预定义的@androidandroid:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"主题: . 在这种情况下,请确保您的活动Activity()不扩展AppCompatActivity()

于 2021-09-29T19:45:51.347 回答
1

包括android api 30,这对我有用

if (Build.VERSION.SDK_INT < 16) {
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
    } else if (Build.VERSION.SDK_INT < 30) {
        window.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
        actionBar?.hide()
    } else {
        window.decorView.windowInsetsController?.hide(WindowInsets.Type.statusBars())
    }
于 2021-04-25T02:07:48.880 回答
1

这是关于在 Android 4.0 及更低版本和 Android 4.1 及更高版本上隐藏状态栏的官方文档

请看一下:

https://developer.android.com/training/system-ui/status.html

于 2017-01-19T22:21:26.533 回答
0

这个解决方案对我有用:)

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 19) {
           getWindow().setFlags(AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT, AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT);
           getWindow().getDecorView().setSystemUiVisibility(3328);
    }else{
           requestWindowFeature(Window.FEATURE_NO_TITLE);
           this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    DataBindingUtil.setContentView(this, R.layout.activity_hse_video_details);
于 2017-10-08T05:56:29.170 回答
0

我知道我回答得太晚了。为此,我在相关的 java 文件中使用以下代码

Objects.requireNonNull(getSupportActionBar()).hide();
于 2021-08-29T20:04:10.137 回答
0
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // If the Android version is lower than Jellybean, use this call to hide
    // the status bar.
    if (Build.VERSION.SDK_INT < 16) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
       View decorView = getWindow().getDecorView();
       // Hide the status bar.
       int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
       decorView.setSystemUiVisibility(uiOptions);
       // Remember that you should never show the action bar if the
       // status bar is hidden, so hide that too if necessary.
       ActionBar actionBar = getActionBar();
       actionBar.hide();
    }

    setContentView(R.layout.activity_main);

}
...
}
于 2017-11-08T15:15:05.613 回答
0

我们无法阻止状态在 (4.4+) kitkat 或更高版本的设备中以全屏模式出现,因此请尝试破解以阻止状态栏扩展。

解决方案非常大,所以这里是SO的链接:

StackOverflow:在 android 4.4+ 或 kitkat 中全屏隐藏状态栏

于 2016-06-14T10:24:36.323 回答
0

隐藏状态栏

private void hideSystemBars() {
    WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
    WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
    if (windowInsetsController == null) {
        return;
    }
    // Configure the behavior of the hidden system bars
    windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
    // Hide both the status bar and the navigation bar
    windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
}

显示状态栏

private void showSystemBars() {
    WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
    WindowInsetsControllerCompat windowInsetsController = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
    if (windowInsetsController == null) {
        return;
    }
    // Configure the behavior of the hidden system bars
    windowInsetsController.setSystemBarsBehavior(WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
    // Hide both the status bar and the navigation bar
    windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
}

用于带屏幕的顶级相机切割

<item name="android:windowLayoutInDisplayCutoutMode" tools:ignore="NewApi">shortEdges</item>
于 2022-02-16T10:26:44.360 回答
0

在 Style.xml 文件中添加或替换

<item name="android:statusBarColor">@android:color/transparent</item>
于 2021-06-17T05:02:54.073 回答
0

我坚持使用干净且可扩展的方法来显示和隐藏系统 UI,适用于不同的 Android Api 级别:

object SystemBarsCompat {
    private val api: Api =
        when {
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> Api31()
            Build.VERSION.SDK_INT == Build.VERSION_CODES.R -> Api30()
            else -> Api()
        }

    fun hideSystemBars(window: Window, view: View, isImmersiveStickyMode: Boolean = false) =
        api.hideSystemBars(window, view, isImmersiveStickyMode)

    fun showSystemBars(window: Window, view: View) = api.showSystemBars(window, view)

    fun areSystemBarsHidden(view: View): Boolean = api.areSystemBarsHidden(view)

    @Suppress("DEPRECATION")
    private open class Api {
        open fun hideSystemBars(window: Window, view: View, isImmersiveStickyMode: Boolean = false) {
            val flags = View.SYSTEM_UI_FLAG_FULLSCREEN or
                View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_HIDE_NAVIGATION

            view.systemUiVisibility = if (isImmersiveStickyMode) {
                flags or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            } else {
                flags or
                    View.SYSTEM_UI_FLAG_IMMERSIVE or
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            }
        }

        open fun showSystemBars(window: Window, view: View) {
            view.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        }

        open fun areSystemBarsHidden(view: View) = view.systemUiVisibility and View.SYSTEM_UI_FLAG_HIDE_NAVIGATION != 0
    }

    @Suppress("DEPRECATION")
    @RequiresApi(Build.VERSION_CODES.R)
    private open class Api30 : Api() {

        open val defaultSystemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE

        override fun hideSystemBars(window: Window, view: View, isImmersiveStickyMode: Boolean) {
            window.setDecorFitsSystemWindows(false)
            view.windowInsetsController?.let {
                it.systemBarsBehavior =
                    if (isImmersiveStickyMode) WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
                    else defaultSystemBarsBehavior
                it.hide(WindowInsets.Type.systemBars())
            }
        }

        override fun showSystemBars(window: Window, view: View) {
            window.setDecorFitsSystemWindows(false)
            view.windowInsetsController?.show(WindowInsets.Type.systemBars())
        }

        override fun areSystemBarsHidden(view: View) = !view.rootWindowInsets.isVisible(WindowInsets.Type.navigationBars())
    }

    @RequiresApi(Build.VERSION_CODES.S)
    private class Api31 : Api30() {
        override val defaultSystemBarsBehavior = WindowInsetsController.BEHAVIOR_DEFAULT
    }
}

例如,要隐藏系统栏,可以从 a 调用它Fragment

SystemBarsCompat.hideSystemBars(requireActivity().window, view)
于 2022-02-05T13:58:42.640 回答
0

我们可以使用 setSystemUiVisibility() 在 Android 4.1(API 级别 16)及更高版本中隐藏状态栏

window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN

根据 google 文档,如果状态栏被隐藏,我们不应该显示操作栏,因此如有必要也将其隐藏。

actionBar?.hide()
于 2021-06-27T15:32:31.427 回答
0

如果您使用的是Compose,那么您可以导入

implementation "com.google.accompanist:accompanist-systemuicontroller:0.17.0"

然后在你的屏幕上写

val systemUiController = rememberSystemUiController()
systemUiController.isStatusBarVisible = false
于 2021-10-18T03:46:43.833 回答
0

如果您参考Google 文档,您可以在 android 4.1 及更高版本中使用此方法,请在 setContentView() 之前调用此方法

public void hideStatusBar() {
    View view = getWindow().getDecorView();
    int uiOption = View.SYSTEM_UI_FLAG_FULLSCREEN;
    view.setSystemUiVisibility(uiOption);
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.hide();
    }
}
于 2020-07-12T14:03:19.687 回答
0

用于Manifest

android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen"
于 2018-01-10T20:08:27.113 回答
-1

在 res -> values ->styles.xml 下

里面的style body标签粘贴

<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
于 2018-03-20T08:39:12.973 回答
-1
requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
于 2019-02-05T14:32:13.483 回答