Ali Soleimani
Ali Soleimani

Reputation: 300

Color Primary Dark is not working

I set the color primary dark before in my color.xml file and the status bar color was the same color that color primary dark was too! but a few hours ago, I made a menu resource file and for creating a search button in my toolbar!. when I run my code, I saw that the color primary dark disappeared and is not working. I searched a lot to understand what is the problem but I did not find any thing. please guide me to fix this problem.

style.xml:

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">

</style>

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

</style>

style-v21 :

<style name="AppTheme" parent="AppTheme.Base">
    <!-- Customize your theme here. -->
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:navigationBarColor">@color/colorNavBar</item>
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>

toolbar.xml :

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary"
android:layout_gravity="start">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/toolbar_title"
    android:text="@string/app_name_persian"
    android:textSize="19sp"
    android:textStyle="bold"
    android:textColor="@android:color/white"
    android:layout_gravity="right"/>
<EditText
    android:layout_marginRight="20dp"
    android:id="@+id/searchEditText"
    android:layout_width="180dp"
    android:textSize="10sp"
    android:hint="@string/search_hint"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="invisible"/>

color.xml :

<resources>
<color name="colorPrimary">#0cac77</color>
<color name="colorPrimaryDark">#73ac95</color>
<color name="colorAccent">#20efd6</color>
<color name="colorNavBar">#73ac95</color>
<color name="colorNavDrawerBackColor">#f4f3f3</color>
<color name="colorCreationDate">#4acc82</color>
<color name="colorDeadDate">#d77177</color>
<color name="colorDutyName">#e5e8e9</color>

Upvotes: 4

Views: 5922

Answers (5)

Ali Soleimani
Ali Soleimani

Reputation: 300

I found the answer!

I used android:fitsSystemWindows="true" in the root layout's attributes in main activity's xml to avoiding window movement when the user is typing with keypad, but I fixed it with putting this android:windowSoftInputMode="adjustPan" in activity's attributes in Manifest file!

Upvotes: 0

Vitor Braga
Vitor Braga

Reputation: 2212

Here in my code, as mentioned by @TheAnonymous010, I've just set the main layout to CoordinatorLayout (I've set it as the parent of my RelativeLayout).

<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"
    android:fitsSystemWindows="true"
    tools:context="com.example.MyActivity">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark"
        android:orientation="vertical"
        android:padding="15dp">

        ....
        ....

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

Upvotes: 1

Asif Patel
Asif Patel

Reputation: 1764

Just replace android:background from android:background="?attr/colorPrimary" to android:background="@color/colorPrimaryDark".

Upvotes: 0

tachyonflux
tachyonflux

Reputation: 20211

Don't override your theme. Remove this property from your Toolbar:

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

Upvotes: 0

TheAnonymous010
TheAnonymous010

Reputation: 725

If you are trying to change the color of the toolbar, you might want to change the android:background from android:background="?attr/colorPrimary" to android:background="?attr/colorPrimaryDark".

Upvotes: 0

Related Questions