0

I create app from the template with Design Support Library and gonna change the color of the android.support.v7.widget.Toolbar to pure red.

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

It works, but color is D62628 instead FF0000. What's wrong?

Update: Ok, I try to do it via colorPrimary. Set color in colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#ffff0000</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
</resources>

The same history:

screenshot

Pankaj
  • 7,908
  • 6
  • 42
  • 65
tse
  • 5,769
  • 6
  • 38
  • 58

3 Answers3

0
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"

    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

and add in ur color.xml

<resources>
    <color name="colorPrimary">#FF0000</color>


</resources>
Shivanshu Verma
  • 609
  • 5
  • 19
0

Do it like this in your onCreate() method.

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
        } 
        setContentView(R.layout.your_layout);
.
.
.
}
Pankaj
  • 7,908
  • 6
  • 42
  • 65
0

The answer will be not about Android, it will be about the tools. Color picker in Android Studio takes wrong color. As I understand it takes color from screen, that affected by calibration settings, not from screenshot.

When I picked color inside the Gimp editor, it shows me the same color that I set in styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/wrs_color_primary</item>
    ...
</style>
<color name="wrs_color_primary">#ff9900</color>

enter image description here

tse
  • 5,769
  • 6
  • 38
  • 58