首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Marshmallow上的NoActionBar

Marshmallow上的NoActionBar
EN

Stack Overflow用户
提问于 2019-02-06 16:42:56
回答 2查看 96关注 0票数 0

我想隐藏actionBar,但它只是有点褪色了:

风格:

代码语言:javascript
复制
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/background</item>
    <item name="colorPrimaryDark">@color/background</item>
    <item name="android:windowBackground">@color/background</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
</style>

清单:

代码语言:javascript
复制
<application
    android:configChanges="orientation|screenSize|layoutDirection"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

结果:

只是有点褪色,我只对棉花糖设备有问题(6.0.1)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-06 16:58:03

您仍然在使用带有Actionbar的AppTheme

将此样式添加到样式文件

代码语言:javascript
复制
 <style name = "NoActionBar" parent = "@android:style/Theme.Holo.Light">
        <item name = "android:windowActionBar">false</item>
        <item name = "android:windowNoTitle">true</item>
    </style>

和您需要更改

android:theme="@style/AppTheme"

清单中的

android:theme = "@style/NoActionBar"

代码语言:javascript
复制
<application
    android:configChanges="orientation|screenSize|layoutDirection"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/NoActionBar">

    <activity
        android:name=".MainActivity"
        android:screenOrientation="portrait"
        android:theme="@style/NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

还有另一种隐藏操作栏的方法,如:

1.

代码语言:javascript
复制
<activity android:name=".MainActivity" 
          android:theme="@style/Theme.AppCompat.Light.NoActionBar" >
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />

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

2.使用隐藏方法

代码语言:javascript
复制
 // Hide ActionBar

if (getSupportActionBar() != null) {
            getSupportActionBar().hide();
        }

3.或使用 requestWindowFeature(Window.FEATURE_NO_TITLE);

代码语言:javascript
复制
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Hide ActionBar
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.activity_main);
    }
票数 0
EN

Stack Overflow用户

发布于 2019-02-07 08:11:06

创建一个新的样式xml,并将其更改如下

Theme.AppCompat.Light.NoActionBar

也许会管用..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54558532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档