无法更改Android中少数屏幕的状态栏颜色

时间:2018-12-15 08:59:56

标签: android android-actionbar android-theme android-statusbar

下面有一个我想要更改显示栏颜色的应用程序,它适合MainActivity屏幕,但对于所有其他活动屏幕,它都显示为白色,请参见下图:

enter image description here

以下是我的style.xml:

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

<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>  
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" >
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" >
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kushal.boulders">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application
        android:name=".App"
        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">
        <uses-library android:name="android.test.runner" />
        <activity
            android:name=".activities.SplashActivity"
            android:noHistory="true"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.LoginActivity"
            android:label="@string/title_activity_authentication"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity
            android:name=".activities.RegistrationActivity"
            android:label="@string/title_activity_registration"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity
            android:name=".activities.UserProfileActivity"
            android:label="@string/title_activity_userprofile"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity
            android:name=".activities.MemberProfileActivity"
            android:label="@string/title_activity_member_profile"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity
            android:name=".activities.AddMemberActivity"
            android:label="@string/title_activity_addmember"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity
            android:name=".activities.EditMemberProfileActivity"
            android:label="@string/title_activity_editmember"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity
            android:name=".activities.AboutActivity"
            android:label="@string/title_activity_about"
            android:theme="@style/AppTheme.NoActionBar"></activity>
    </application>
</manifest>

AddMemberActivity.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.kushal.boulders.activities.AddMemberActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp">

    <View
        android:id="@+id/view_amf_greenArea"
        android:layout_width="match_parent"
        android:layout_height="220dp"
        android:background="@color/colorAccent" />

    <View
        android:id="@+id/view_amf_greyArea"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/view_amf_greenArea"
        android:background="@color/colorGrey"/>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_addMember"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        app:layout_anchor="@+id/rl_mainLayout"
        app:layout_anchorGravity="top|right"
        android:layout_margin="@dimen/fab_margin"
        android:layout_marginBottom="80dp"
        android:layout_marginLeft="@dimen/fab_margin"
        android:layout_marginRight="@dimen/fab_margin"
        app:backgroundTint="@color/colorAccent"
        app:srcCompat="@drawable/ic_save" />

    <RelativeLayout
        android:id="@+id/rl_mainLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:orientation="vertical"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="40dp"
        android:layout_marginBottom="10dp">

        <RelativeLayout
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true"
            android:elevation="12dp">


            <android.support.v7.widget.CardView
                android:id="@+id/cv_amf_memberAvatar"
                style="@style/MemberItem_CardViewStyle"
                android:layout_width="124dp"
                android:layout_height="124dp"
                android:layout_centerHorizontal="true"
                app:cardCornerRadius="60dp"
                app:contentPadding="2dp"
                android:elevation="10dp">

            <android.support.v7.widget.CardView
                android:id="@+id/cv_amf_memberAvatarHolder"
                style="@style/MemberItemAvatarHolder_CardViewStyle"
                android:layout_width="118dp"
                android:layout_height="118dp"
                android:layout_margin="1dp"
                android:layout_centerHorizontal="true"
                app:cardCornerRadius="60dp"
                app:contentPadding="2dp"
                android:elevation="10dp">


                <ImageView
                    android:id="@+id/iv_amf_memberAvatar"
                    android:contentDescription="Member Profile Picture"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:src="@drawable/ic_member" />


            </android.support.v7.widget.CardView>
            </android.support.v7.widget.CardView>

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab_rotateImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                app:fabSize="mini"
                android:scaleType="centerCrop"
                app:backgroundTint="@color/colorGrey"
                app:srcCompat="@drawable/ic_rotateright" />

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fab_amf_addImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:fabSize="mini"
                android:scaleType="centerCrop"
                app:srcCompat="@drawable/ic_add_new_member"
                app:layout_anchor="@id/fab_rotateImage"
                app:backgroundTint="@color/colorGrey"
                app:layout_anchorGravity="bottom" />


        </RelativeLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="vertical">

            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="100dp"
                android:backgroundTint="@color/colorAccent"
                app:cardCornerRadius="30dp"
                app:contentPadding="2dp">

             <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:cardCornerRadius="30dp"
                app:contentPaddingBottom="15dp"
                app:contentPaddingLeft="15dp"
                app:contentPaddingRight="15dp"
                app:contentPaddingTop="15dp">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:layout_gravity="center_horizontal"
                    android:paddingBottom="10dp"
                    android:paddingLeft="0dp"
                    android:paddingRight="20dp"
                    android:paddingTop="10dp">

                    <TextView
                    android:id="@+id/lbl_amf_memberFirstName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="First Name"
                    android:textColor="@android:color/black"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:drawablePadding="3dp"
                    android:layout_marginBottom="2dp"
                        android:layout_marginTop="10sp"/>

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/edt_amf_memberFirstName"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:singleLine="true"
                            android:textSize="14sp"
                            android:layout_marginStart="10sp"
                            android:layout_marginLeft="10sp"/>
                    </android.support.design.widget.TextInputLayout>

                    <TextView
                    android:id="@+id/lbl_amf_memberLastName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Last Name"
                    android:textColor="@android:color/black"
                    android:textSize="14sp"
                    android:textStyle="bold"
                    android:drawablePadding="3dp"
                    android:layout_marginBottom="2dp"
                    />

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/edt_amf_memberLastName"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:singleLine="true"
                            android:textSize="14sp"
                            android:layout_marginStart="10sp"
                            android:layout_marginLeft="10sp"/>
                    </android.support.design.widget.TextInputLayout>


                    <TextView
                        android:id="@+id/lbl_amf_memberPhone"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Phone"
                        android:textColor="@android:color/black"
                        android:textSize="14sp"
                        android:textStyle="bold"
                        android:drawableStart="@drawable/ic_phone"
                        android:drawableLeft="@drawable/ic_phone"
                        android:drawablePadding="3dp"
                        android:layout_marginBottom="2dp"
                        />

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/edt_amf_memberPhone"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:singleLine="true"
                            android:textSize="14sp"
                            android:layout_marginStart="10sp"
                            android:layout_marginLeft="10sp"
                            android:inputType = "phone"/>
                    </android.support.design.widget.TextInputLayout>

                    <TextView
                        android:id="@+id/lbl_amf_memberEmail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Email"
                        android:textColor="@android:color/black"
                        android:textSize="14sp"
                        android:textStyle="bold"
                        android:drawableStart="@drawable/ic_email"
                        android:drawableLeft="@drawable/ic_email"
                        android:drawablePadding="3dp"
                        android:layout_marginBottom="2dp"/>

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/edt_amf_memberEmail"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:singleLine="true"
                            android:textSize="14sp"
                            android:layout_marginStart="10sp"
                            android:layout_marginLeft="10sp"/>

                    </android.support.design.widget.TextInputLayout>


                    <TextView
                        android:id="@+id/lbl_amf_memberAddress"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Address"
                        android:textColor="@android:color/black"
                        android:textSize="14sp"
                        android:textStyle="bold"
                        android:drawableStart="@drawable/ic_address"
                        android:drawableLeft="@drawable/ic_address"
                        android:drawablePadding="3dp"
                        android:layout_marginBottom="2dp"/>

                    <android.support.design.widget.TextInputLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/edt_amf_memberAddress"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:textSize="14sp"
                            android:layout_marginStart="10sp"
                            android:layout_marginLeft="10sp"/>
                    </android.support.design.widget.TextInputLayout>

                    <TextView
                        android:id="@+id/lbl_amf_memberCycleStartDate"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Cycle Starting on"
                        android:textColor="@android:color/black"
                        android:textSize="14sp"
                        android:textStyle="bold"
                        android:drawableStart="@drawable/ic_date_start"
                        android:drawableLeft="@drawable/ic_date_start"
                        android:drawablePadding="3dp"
                        android:layout_marginBottom="2dp"/>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/holder_amf_memberCycleStartDate"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/edt_amf_memberCycleStartDate"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:singleLine="true"
                            android:textSize="14sp"
                            android:layout_marginStart="10sp"
                            android:layout_marginLeft="10sp"
                            android:focusable="false"/>
                    </android.support.design.widget.TextInputLayout>

                    <TextView
                        android:id="@+id/lbl_amf_memberCycleEndDate"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Cycle Ending on"
                        android:textColor="@android:color/black"
                        android:textSize="14sp"
                        android:textStyle="bold"
                        android:drawableStart="@drawable/ic_date_end"
                        android:drawableLeft="@drawable/ic_date_end"
                        android:drawablePadding="3dp"
                        android:layout_marginBottom="2dp"/>

                    <android.support.design.widget.TextInputLayout
                        android:id="@+id/holder_amf_memberCycleEndDate"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp">

                        <EditText
                            android:id="@+id/edt_amf_memberCycleEndDate"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:singleLine="true"
                            android:textSize="14sp"
                            android:layout_marginStart="10sp"
                            android:layout_marginLeft="10sp"
                            android:focusable="false"/>
                    </android.support.design.widget.TextInputLayout>


                </LinearLayout>

             </android.support.v7.widget.CardView>
            </android.support.v7.widget.CardView>

        </LinearLayout>

    </RelativeLayout>

    </RelativeLayout>

</RelativeLayout>

</android.support.design.widget.CoordinatorLayout>

enter image description here

2 个答案:

答案 0 :(得分:1)

请确保您没有覆盖<item name="android:statusBarColor">中的style.xml。之后,最好在每个活动的布局中将CoordinatorLayoutAppBarLayout一起使用。尝试如下定义AppTheme.NoActionBar样式:

style.xml

...

<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" />

在每个活动中,按照以下代码段定义根布局和工具栏:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="path.to.Activity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <!-- include content here with match_parent width and height -->

</android.support.design.widget.CoordinatorLayout>

最后,在manifest.xml中,将android:theme="@style/AppTheme.NoActionBar"设置为整个应用程序(在应用程序标签中),并为应该使用不同主题的每个活动覆盖它。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kushal.boulders">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <application
        android:name=".App"
        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.NoActionBar">

        <uses-library android:name="android.test.runner" />

        <activity
            android:name=".activities.SplashActivity"
            android:noHistory="true"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.MainActivity"
            android:label="@string/app_name"
            android:launchMode="singleTop">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
            </intent-filter>
        </activity>
        <activity
            android:name=".activities.LoginActivity"
            android:label="@string/title_activity_authentication"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.RegistrationActivity"
            android:label="@string/title_activity_registration"
            android:screenOrientation="portrait"/>
        <activity
            android:name=".activities.UserProfileActivity"
            android:label="@string/title_activity_userprofile"/>
        <activity
            android:name=".activities.MemberProfileActivity"
            android:label="@string/title_activity_member_profile"/>
        <activity
            android:name=".activities.AddMemberActivity"
            android:label="@string/title_activity_addmember"/>
        <activity
            android:name=".activities.EditMemberProfileActivity"
            android:label="@string/title_activity_editmember"/>
        <activity
            android:name=".activities.AboutActivity"
            android:label="@string/title_activity_about"/>
    </application>
</manifest>

答案 1 :(得分:0)

请使用

AppTheme.NoActionBar

带有代码。您还可以选择相同的表单布局主题选项,它将更改所有样式代码。