我想要隐藏的标题栏对于我的一些活动。问题是我应用一个风格给我所有的活动,因此我不能简单地设置主题, @android:style/Theme.NoTitleBar.

使用 NoTitleBar 主题作为父母对我的风格将删除标题吧从我所有的活动。

我可以设置一个没有标题式的项目的地方吗?

有帮助吗?

解决方案 3

我现在做了以下。

我宣布一个风格继承一切从我的普通样式,然后禁用标题栏。

<style name="generalnotitle" parent="general">
    <item name="android:windowNoTitle">true</item>
</style>

现在我可以将此样式设置为中,我想隐藏标题栏重写应用广泛的风格和继承所有其他样式信息每个活动,为此在样式代码没有重复。

要将该样式应用到特定的活动,开放AndroidManifest.xml和下面的属性添加到activity标签;

<activity
    android:theme="@style/generalnotitle">

其他提示

为此在您的onCreate()方法。

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

//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here); 

thisActivity

您可以修改您的AndroidManifest.xml

<activity android:name=".MainActivity"
          android:label="@string/app_name"
          android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">

或使用android:theme="@android:style/Theme.Black.NoTitleBar"如果你不需要全屏活动。

注意:如果您之前已经使用了“默认”视图,你应该也从AppCompatActivity父类更改为Activity

我不喜欢this.requestWindowFeature(Window.FEATURE_NO_TITLE);因为标题栏出现短暂,然后消失。

我也并不喜欢android:theme="@android:style/Theme.NoTitleBar",因为我失去了所有的3.0+全息的改变,新设备的用户已经习惯于。所以,我碰到这个解决方案就来了。

在您的 RES /值文件夹制作名为 styles.xml (如果它不存在)。在该文件中放置以下代码:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Default" parent="@android:style/Theme"></style>
    <style name="Theme.NoTitle" parent="@android:style/Theme.NoTitleBar"></style>
    <style name="Theme.FullScreen" parent="@android:style/Theme.NoTitleBar.Fullscreen"></style>
</resources>

接下来,创建一个的 RES /值-V11 与另一个的 styles.xml 文件(再一次,这可能已经存在)。在该文件中放置以下代码:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Default" parent="@android:style/Theme.Holo"></style>
    <style name="Theme.NoTitle" parent="@android:style/Theme.Holo.NoActionBar"></style>
    <style name="Theme.FullScreen" parent="@android:style/Theme.Holo.NoActionBar.Fullscreen"></style>
</resources>

如果你的目标4.0+,创建一个 RES /值-V14 又一 styles.xml 文件(是的,它可能已经在那里)文件夹中。在该文件中放置以下代码:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="Theme.Default" parent="@android:style/Theme.Holo.Light"></style>
    <style name="Theme.NoTitle" parent="@android:style/Theme.Holo.Light.NoActionBar"></style>
    <style name="Theme.FullScreen" parent="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen"></style>
</resources>

最后,所有创建这些文件,请打开您的 AndroidManifiest.xml 文件,你可以添加代码:

android:theme="@style/Theme.NoTitle"

该活动的活动标签,你想为没有标题或应用程序标记,如果你想让它应用于整个应用程序。

现在,您的用户将获得与屏幕的设备版本相关的主题布局你的愿望。

P.S。改变值android:theme="@style/Theme.FullScreen"将具有相同的效果,而且还除去通知栏。

在标题栏可以删除,在两个方面提到的开发人员安卓页:

manifest.xml 文件:

  1. 添加以下 application 如果你想要删除它的所有活动中的应用程序:

    <application android:theme="@android:style/Theme.Black.NoTitleBar">
    
  2. 或用于特定活动:

    <activity android:theme="@android:style/Theme.Black.NoTitleBar">
    

正确的答案可能是为了不延长ActionbarActivity而延长刚刚活动


如果你仍然使用作条活动 似乎这是工作:

@Override
protected void onCreate(Bundle savedInstanceState) {          
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); //<< this
    setContentView(R.layout.activity_main);
}

看来这个工作:

styles.xml:

   <style name="AppBaseTheme" parent="Theme.AppCompat.Light" >
          <item name="android:windowNoTitle">true</item>   <!-- //this -->     
   </style>

我可以做为斯科特*比格斯写的。这种工作。除了没有主题。我的意思是设置菜单的背景是透明的:

只是改变

public class MainActivity extends ActionBarActivity {

活动或FragmentActivity

public class MainActivity extends Activity  {

但是我可以让它看起来不够好使用材料的设计,而不是删除 的作条:https://gist.github.com/shimondoodkin/86e56b3351b704a05e53

  1. 设置标的应用程序
  2. 集的颜色行动栏相匹配的设计。
  3. 设置图设置菜单
  4. 增加更多的图标(按钮上)

它是通过实例的材料设计的兼容性作条的造型。

如果您使用this.requestWindowFeature(Window.FEATURE_NO_TITLE)用户仍然可以看到标题栏只是片刻推出动画期间,当通过onCreate活动开始。如果使用@android:style/Theme.Black.NoTitleBar如图然后标题栏的下方不会发射动画过程中被显示。

<activity 
    android:name=".MainActivity" 
    android:label="My App"
    android:theme="@android:style/Theme.Black.NoTitleBar"
    android:screenOrientation="portrait">

上面的例子显然会覆盖现有的应用程序的主题,如果您有现有的主题,再加入<item name="android:windowNoTitle">true</item>它。

什么对我说:

1-在styles.xml:

 <style name="generalnotitle" parent="Theme.AppCompat.Light" >
          <item name="android:windowNoTitle">true</item>   <!-- //this -->     
   </style>

2-在重置

@Override
protected void onCreate(Bundle savedInstanceState) {          
    super.onCreate(savedInstanceState);
    getSupportActionBar().hide(); //<< this
    setContentView(R.layout.activity_main);
}
  1. 在清单继承的风格:

    <activity android:name=".MainActivity" android:theme="@style/generalnotitle">
    

当我尝试使用所有这些高upvoted答案我的应用程序总是崩溃。 (我认为它有什么做的?“@android:风格”)

对我来说,最好的解决方案是使用以下内容:

android:theme="@style/Theme.AppCompat.NoActionBar"

没有页眉/标题栏了。只要将其放置在<application>...</application><activity>...</activity>取决于如果您(不)想在整个应用程序或只是一个特定的活动。

创建主题如下。

 <!-- Variation on the Light theme that turns off the title -->
<style name="MyTheme" parent="android:style/Theme.Black">
    <item name="android:windowNoTitle">true</item>
</style>

添加

<item name="android:windowNoTitle">true</item>

内部AppTheme(styles.xml)

只需使用getActionBar().hide();在主活动onCreate()方法。

您只需要在Style.xml变化AppTheme风格,如果你从DarkActionBar替换定义

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

NoActionBar

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

AppTheme在AndroidManifast.xml定义

有关AppCompat,下面的解决方案为我工作:

添加新的主题风格,在你styles.xml和集parent="Theme.AppCompat.NoActionBar"没有行动起来吧。

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimary</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/colorPrimary</item>

</style>

结果现在实现了相同的主题风格,闪屏活动androidManifest.xml

<activity
        android:name=".ActivityName"
        android:theme="@style/SplashTheme"> // apply splash them here 

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

下面是结果:

您可以在您的Java文件中使用此代码

在设置之前加入这一行或加载视图

requestWindowFeature(Window.FEATURE_NO_TITLE); 
setContentView(R.layout.activity_main);

在您的onCreate方法,使用下面的片段:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);

添加这两个为主题的使用:

    <item name="windowActionBar">false</item>
    <item name="android:windowNoTitle">true</item>

添加这种风格到您的style.xml文件

 <style name="AppTheme.NoActionBar">
     <item name="windowActionBar">false</item>
     <item name="windowNoTitle">true</item>
 </style>

在perticular活动中,你不希望看到标题栏,如象下面这样引用这个样式的名称到您的AndroidManifest.xml后。

<activity android:name=".youractivityname"
     android:theme="@style/AppTheme.NoActionBar">
</activity>

或者,如果你想隐藏/显示在任何一点的标题栏:

private void toggleFullscreen(boolean fullscreen)
{
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    if (fullscreen)
    {
        attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    else
    {
        attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    }
    getWindow().setAttributes(attrs);
}

我使用的支承插件工具栏V7。 因此,为了能够删除或隐藏,我们需要写这个标题。

Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);

//Remove¡ing title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);

在我的情况下,如果你正在使用的Android 2.1的工作室,和你的编译SDK版本是6.0,那么就到你的manifest.xml文件,并更改下面的代码:

下面是代码:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.lesterxu.testapp2">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

这里是剪断拍摄(见高亮代码): “在这里输入的图像描述”

这解决了问题

在清单我的活动:

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

在式下 “AppTheme” 名:

<resources>

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

</resources>

要隐藏标题都和动作条我这样做:

在清单的活动标记:

android:theme="@style/AppTheme.NoActionBar"

的setContentView之前在Activity.java:

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

即,

//删除标题栏

  

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

//删除通知栏

  。

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

注意:您需要setContentView之前保持这些行

第一个答案是闪石。 这里是我的解释: 添加:

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

在onCreate()方法

之前:

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);

(不只是的setContentView之前) 如果不这样做U将得到forceclose。 1这个答案。

我发现了两个原因可能会出现此错误。

<强>一的窗口标志被设置已设置内部super.onCreate(savedInstanceState);在这种情况下,你可能想使用的命令的顺序如下:

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

super.onCreate(savedInstanceState);

二。您有标题栏里面的返回/向上按钮,这意味着当前的活动是另一活动的分层孩子,在这种情况下,你可能想注释掉或删除此行的从onCreate方法内的代码。

getActionBar().setDisplayHomeAsUpEnabled(true);

这是完整的代码看起来怎么样。注意android.view.Window的进口。

package com.hoshan.tarik.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
    }
}

添加主题@风格/ Theme.AppCompat.Light.NoActionBar在您的AndroidManifest.xml中像这样

活动
<activity
        android:name=".activities.MainActivity"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    </activity>

如果你做了什么用户的偏航道格·保罗的发言权,那么你必须有记住,窗口功能,必须在调用的setContentView进行设置。如果没有,你会得到一个异常。

加载在manifiest文件,

  android:theme="@android:style/Theme.Translucent.NoTitleBar"

添加下列行到Java文件,

  this.requestWindowFeature(Window.FEATURE_NO_TITLE);

咳咳,你可以应用主题,以个人活动中 XML 如无标题。换句话说,把它拿出来你的应用程序标签,打开标签声明,并把它在希望的活动标签。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top