在android中启用和禁用标题栏

Ash*_*win 1 android android-manifest android-layout

我想根据活动的入口点启用和禁用标题栏.我该怎么做(可能是在xml或代码中)?提前致谢.

Pra*_*tik 7

你可以像这样隐藏标题栏

//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)

或者像这样修改xml文件

<activity android:name=".MainActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
Run Code Online (Sandbox Code Playgroud)

或者像这样使用带有xml文件的样式

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)


Vin*_*tti 5

试试这个..它是一个黑客..

titleView = getWindow().findViewById(android.R.id.title);
    if (titleView != null) {
        ViewParent parent = titleView.getParent();
        if (parent != null && (parent instanceof View)) {
         View parentView = (View)parent;
         parentView.setVisibility(View.GONE);
    }
Run Code Online (Sandbox Code Playgroud)