在Android中更改状态栏颜色 [英] Change status bar color in Android

查看:86
本文介绍了在Android中更改状态栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Android应用程序,现在我想更改状态栏(屏幕上方显示无线和区域信号,电池状态等的状态栏),但是它不起作用。

I'm building an Android application and right now I want to change the status bar (the one on top of the screen that show wireless and area signals, battery status, etc) but it is not working.

在XML文件的预览中,它为条形显示不同的颜色(我要使用的橙色阴影),但是当我在模拟器和单元格中运行应用程序时手机颜色保持白色。

On the preview of the XML file it shows a different color (the shade of orange I want to use) for the bar but when I run the application both in the emulator and on my cell phone the color stays white.

我隐藏了操作栏,并在应用程序顶部放置了灰色图像。

I hide the action bar and put a grey image on the top of the app.

这是Android Studio中XML文件的预览

This is the preview in Android Studio for the XML file

这是应用程序的仿真:

这是我的colors.xml:

This is my colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="theme_color">#D8540D</color>
    <color name="toolbar_title_color">#E66800</color>
    <color name="grey">#d3d3d3</color>
    <color name="maroon">#7f0000</color>
    <color name="color_textual">#8D5020</color>
    <color name="chef_bg_color">#F7F7F7</color>
    <color name="line_color">#dddddd</color>

</resources>

这是我的styles.xml:

And this is my styles.xml:

<resources>

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

        <item name="android:statusBarColor">@color/theme_color</item>
        <item name="android:navigationBarColor">@color/theme_color</item>
        <item name="android:colorEdgeEffect">@color/theme_color</item>
    </style>

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

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>

Android Manifest:

Android Manifest:

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

    <uses-permission android:name="android.permission.INTERNET" />

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

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

        <activity android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">

        </activity>

        <activity android:name=".OrderDetails"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">

        </activity>

        <activity android:name=".PastOrderDetails"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">

        </activity>
    </application>

</manifest>


推荐答案

在清单文件中指定主题的所有活动为 NoActionBar

In you manifest file for all the activities you specified theme as NoActionBar.

但是在 NoActionBar 主题内的styles.xml中,您尚未在代码行下方添加:

But in styles.xml inside NoActionBar theme you haven't added below line of code:

< item name = android:statusBarColor> @ color / theme_color< / item>

NoActionBar 主题的样式添加上面的代码行,然后状态栏的颜色肯定会更改。

Add above line of code in style of NoActionBar theme then color of your status bar will change for sure.

但是会的适用于21级以上的api。

But yes it will work for api level 21 and above.

这篇关于在Android中更改状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆