Flanter
Flanter

Reputation: 3

How to get background color from Android's theme?

I am trying to make the gradient in my activity the following way:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:startColor="#c0c0c0"
        android:endColor="#ffffff"
        android:angle="270"/>
</shape>

The bottom part of the gradient should have the same color as the activity and views background. And I quickly realize that #ffffff (white) color is not actually background color in my application! I have made the screenshot and discovered that background is actually #ececec color.

So is there a way to use current system/theme/style background color in my XML files? I don't want to use hardcoded #ececec color because it can be different on other devices and/or Android versions...

Upvotes: 0

Views: 324

Answers (1)

Blo
Blo

Reputation: 11978

You can use these different solutions:

  • Transparent color from android resource: @android:color/transparent
  • Transparent color with hex: #00000000 (the two first 00 make the opacity to transparent)

For more information about hex opacity color, you should read this post.

Upvotes: 2

Related Questions