如何删除android studio中的标题栏?

Jon*_*tto 67 android android-layout android-studio

在我的应用程序中,顶部有溢出菜单的标题栏,但我不需要设置,只有一个屏幕.当我像许多其他问题中描述的那样改变主题时,我得到了旧的2.2主题.我希望现代主题没有顶部的酒吧.

小智 119

转到styles.xml并更改.DarkActionBar.NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

如果颜色与您的应用程序无关,您实际上可以选择

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar" />
Run Code Online (Sandbox Code Playgroud)


小智 55

在清单文件中更改:

    android:theme="@style/AppTheme" >
    android:theme="@style/Theme.AppCompat.NoActionBar"
Run Code Online (Sandbox Code Playgroud)

  • 虽然这很有效,但编辑`styles.xml`文件对大多数人来说可能是更好的选择,因为使用此方法会忽略可能在`styles.xml`文件中的`AppTheme`下设置的任何值.下面的解决方案用`styles.xml`文件中的`NoActionBar`替换父类保留了已经设置的任何预先存在的样式信息. (4认同)

小智 23

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
Run Code Online (Sandbox Code Playgroud)

在调用onCreate()之前工作时setContentView().

否则它会崩溃

  • 这会导致应用崩溃.我把这行放在`super.onCreate .....`和`setContentView .....`之间.它崩溃了 (6认同)

Kam*_*ngh 16

styles.xml文件中,将DarkActionBar更改为NoActionBar

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
Run Code Online (Sandbox Code Playgroud)


小智 12

检查一下

 ActionBar actionBar = getSupportActionBar();
    actionBar.hide();
Run Code Online (Sandbox Code Playgroud)


Zit*_*tro 10

转到项目 -> 应用程序 -> 主 -> 资源 -> 值 -> 样式.xml

如果要为每个视图删除它,请更改此行

 `<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">`
Run Code Online (Sandbox Code Playgroud)

 `<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">`
Run Code Online (Sandbox Code Playgroud)

如果您只想为一个视图制作它,您可以在您的清单数据中更改它。转到 Android -> manifests -> AndroidManifest.xml。执行以下操作:

  1. 搜索您想要获得此类更改的视图 <activity android:name"...">
  2. 添加 android:theme=""@style/Theme.AppCompat.NoActionBar"


XII*_*III 6

在清单文件中更改为:

android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
Run Code Online (Sandbox Code Playgroud)


Rog*_*nde 6

这对我来说是values/styles.xml添加项目的:

       `<item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>`
Run Code Online (Sandbox Code Playgroud)


小智 6

这适合我

getSupportActionBar().hide();
Run Code Online (Sandbox Code Playgroud)


小智 5

  1. 打开样式.xml
  2. 插入
 <style name="no_title" parent="AppTheme">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowContentOverlay">@null</item>
 </style>
Run Code Online (Sandbox Code Playgroud)

您可以更改名称=“---------”

  1. 打开 Androidmafest.xm

    找到 android:theme="@style/AppTheme" 更改为 android:theme="@style/no_title"

  2. 单击菜单栏上的选择主题(MainActivity 附近为绿色)

    • 单击项目主题
    • 单击 no_title (在您的右侧)
    • 单击“确定”


小智 5

对于像我这样的初学者。照我说的去做。来自你的 Android 项目。

应用程序 -> res -> 值 -> style.xml

替换此代码

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Run Code Online (Sandbox Code Playgroud)

享受。


小智 5

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

    getSupportActionBar().hide();

    setContentView(R.layout.activity_main);
Run Code Online (Sandbox Code Playgroud)

只是简单地放在和方法getSupportActionBar().hide(); 之间。super.onCreatesetContentView


Rus*_*tam 4

在清单文件中执行此操作:

<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
Run Code Online (Sandbox Code Playgroud)