Jaythaking
Jaythaking

Reputation: 2102

Status bar always appears black with AppCompatActivity

My status bar always appear black. I tried multiple fix but nothing does the tricks... I can't believe something as simple is that complicated

Here is my Style.xml:

<style name="AppTheme" parent="BaseTheme" />

<style name="BaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/cobalt</item>
    <item name="colorPrimaryDark">@color/cobalt_dark</item>
    <item name="colorControlHighlight">@color/cobalt_light</item>
    
    <item name="colorAccent">@color/cobalt_light</item>
</style>

Here is my v21/style.xml:

<style name="AppTheme" parent="BaseTheme">
    <item name="android:colorControlHighlight">@color/cobalt_light</item>
    
    <item name="android:statusBarColor">@color/cobalt_light</item>
</style>

Here is my Activity:

public class ActivityLogin extends AppCompatActivity {
 //...
}

My manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.plante.android.cobalt"
    android:versionName="7">

    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="21" />

    <application
        android:name=".CobaltApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme”>
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

        <activity
            android:windowSoftInputMode="adjustResize"
            android:name=".activityv2.ActivityLogin"
            android:label="@string/app_name"
            android:screenOrientation="portrait">

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

        <activity
            android:name=".activityv2.ActivityHome"
            android:label="Home"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.nfc.action.TECH_DISCOVERED" />
            </intent-filter>
            <meta-data
                android:name="android.nfc.action.TECH_DISCOVERED"
                android:resource="@xml/nfc_tag_filter" />
        </activity>
        <activity
            android:name=".activityv2.ActivitySplash"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:screenOrientation="portrait"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

Upvotes: 2

Views: 2343

Answers (4)

Stas Lelyuk
Stas Lelyuk

Reputation: 548

Try update your v21/style with this attribute:

<item name="android:statusBarColor">@color/color_primary</item>

Update: After discussion with author we've decided that targetSdkVersion=18 was used. As we can notice from \sdk\extras\android\support\v7\appcompat\res\values\attrs.xml

<!-- Dark variant of the primary branding color. By default, this is the
color applied to the status bar (via statusBarColor) and navigation bar (via 
navigationBarColor). -->
<attr name="colorPrimaryDark" format="color" />

Due to the fact that statusBarColor attribute Added in API level 21 there is no documented way to change status bar color on pre-lollipop.

Upvotes: 1

Jaythaking
Jaythaking

Reputation: 2102

Ok so here was the issue:

defaultConfig {
    applicationId "com.plante.android.cobalt"
    minSdkVersion 17
    targetSdkVersion 18
    versionCode 7
    multiDexEnabled false
    versionName "7"
}

I shall have put api 21 and over for it to work...

Upvotes: 1

Maslada
Maslada

Reputation: 131

You can always just set the colour programmatically if the solution is proving to be illusive.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.WHITE);
}

Upvotes: 1

Gauthier
Gauthier

Reputation: 4978

You should rename your style "BaseTheme" into "AppTheme.Base" so that it overloads the basic application theme.

or in your tag in your manifest file you can add the parameter :

android:theme="@style/BaseTheme"

Upvotes: 2

Related Questions