Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法删除活动中的标题栏_Android_Android Activity_Android Styles_Android Actionbaractivity - Fatal编程技术网

Android 无法删除活动中的标题栏

Android 无法删除活动中的标题栏,android,android-activity,android-styles,android-actionbaractivity,Android,Android Activity,Android Styles,Android Actionbaractivity,我想删除活动顶部的标题。我尝试了这两种方法,但在api级别8中没有 1: 你知道为什么这在api 8上不起作用吗 有一次我设法在api 8中删除了它,但我不记得是怎么删除的 编辑: final ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(false); 解决了问题是this.requestWindowFeature(Window.FEATURE\u NO\u TITLE)在API 8上不

我想删除活动顶部的标题。我尝试了这两种方法,但在api级别8中没有

1:

你知道为什么这在api 8上不起作用吗

有一次我设法在api 8中删除了它,但我不记得是怎么删除的


编辑:

final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
解决了问题是
this.requestWindowFeature(Window.FEATURE\u NO\u TITLE)
在API 8上不起作用,而且
true
也不起作用,但是
actionBar.hide()
起作用,getSupportActionBar()返回null的原因是之前使用了两个选项中的一个,我只是忘记了删除这两个选项。当我删除一个时,我会添加另一个(多么愚蠢的一个!) 谢谢大家!(抱歉英语不好)

在setContentView方法之前使用requestWindowFeature方法。

您的“解决方法”(自己隐藏操作栏)是正常的方法。但是谷歌建议在标题栏隐藏时总是隐藏操作栏。请看这里:

如果您的构建版本低于16,请按如下所示使用它

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);
    }
    setContentView(R.layout.activity_main);
}
...
公共类MainActivity扩展活动{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//如果Android版本低于Jellybean,请使用此调用隐藏
//状态栏。
如果(Build.VERSION.SDK_INT<16){
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
}
setContentView(R.layout.activity_main);
}
...

}

添加到您的清单中:

final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
全屏显示:

        <activity
        android:name="youtpackagename.activityname"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >

编辑:

final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
其工作性能也低于api 8。。我希望这对你有帮助

    <resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->

         <item name="android:windowFullscreen">true</item> <!-- Hides the status bar -->
    </style>

</resources> 

将此添加到您的活动中。使用ActionBarActivity而不是Activity。

对我来说,唯一有效的方法就是这样做:

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


只有说我的主题是NoActionBar的孩子,我才设法消除了actionBar。所有其他方法都失败了。不知道为什么。

我使用ActionBarActivity,可能很重要。检查此链接,不相关,无帮助。检查此链接我知道,我在设置ContentView方法之前使用它,但什么也没有发生。在活动中,此.requestWindowFeature(Window.FEATURE\u no\u TITLE);工作,我使用ActionBarActivity。我试图隐藏actionBar,但getActionBarSupport返回null,似乎我没有actionBar,发布完整的oncreate方法…并且必须在setContentViewFULLSCREEN不是我的问题之前使用上述代码,我的活动已经是全屏的,并且还可以,问题是标题。我尝试了所有,我创建了一个没有NoTitleBar的自定义主题,但不起作用。我没有收到任何错误,但标题仍然在顶部。@阿森纳不创建任何主题,只需在活动标签(清单)中添加
android:theme=“@android:style/theme.NoTitleBar.Fullscreen”
。。它的android默认主题我不能添加主题,因为我使用ActionBarActivity,当我更改主题时,我会得到错误,使用主题除外。AppCompat.getSupportActionBar()返回null。@我终于找到答案了!!但在前面的内容中,我提到了bothgetSupportActionBar()返回null。您是否删除了这个.requestWindowFeature(Window.FEATURE\u NO\u TITLE);你不必使用其他任何东西。我已经用api 8和api 19尝试过了。这对它们都有效。删除此.requestWindowFeature(Window.FEATURE\u NO\u TITLE);我删除了这个.requestWindowFeature(Window.FEATURE\u NO\u TITLE);但是getSupportActionBar()仍然返回null。
{
  ActionBar actionBar = getActionBar(); or getSupportActionBar();
  actionBar.hide();
}
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
    <resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->

         <item name="android:windowFullscreen">true</item> <!-- Hides the status bar -->
    </style>

</resources> 
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;


public class MainActivity extends ActionBarActivity {

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

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