9

我想删除我的活动顶部的标题。我尝试了这两种工作方式,但不是在 api 8 级。

1:

<style name="NOtitleTheme" parent="Theme.AppCompat.Light">
<item name="android:windowFullscreen">true</item>
   <item name="android:windowNoTitle">true</item> </style>

2:

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

知道为什么这不起作用api 8吗?

一旦我设法将其删除api 8,但我不记得如何删除它。


编辑:

解决了!问题是 this.requestWindowFeature(Window.FEATURE_NO_TITLE)在 API 8 上不起作用,也<item name="android:windowNoTitle">true</item>不起作用,但 actionBar.hide()有效,getSupportActionBar() 返回 null 的原因是之前使用了两个选项之一,我只是忘记删除两者。当我删除一个时,我添加另一个(多么愚蠢!)谢谢大家!(抱歉英语不好)

4

5 回答 5

10

添加到您的清单:

全屏:

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

或(单独隐藏标题)

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

或者在setContentView方法之前使用下面的代码。

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

或者

{
  ActionBar actionBar = getActionBar(); or getSupportActionBar();
  actionBar.hide();
}

编辑:

final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);

它在 api 8 下也能正常工作。我希望这会对你有所帮助

于 2014-08-04T12:55:50.190 回答
3
    <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> 

在您的样式 xml 中将此添加到您的 AppTheme。

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();
    }

}

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

于 2014-08-04T13:07:21.773 回答
1

对我来说,唯一可行的方法是这样做:

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

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

于 2017-11-15T23:12:21.363 回答
0
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

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

于 2014-08-04T12:50:46.823 回答
0

您的“解决方法”(自己隐藏 actionBar)是正常方式。但谷歌建议在隐藏标题栏时始终隐藏操作栏。看看这里: https ://developer.android.com/training/system-ui/status.html

如果您的构建版本小于 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);
}
...

}

于 2014-08-04T12:53:28.077 回答