LoginSignup
1
0

More than 3 years have passed since last update.

Androidで色の透過率を指定する

Last updated at Posted at 2019-08-20

Color.argbで指定する方法

example.kt
import android.graphics.Color

Color.argb(128, 51, 51, 51)

引数として以下の4つの値を10進数(0〜255)のintで渡す。

  • alpha 透過率
  • red 赤
  • green 緑
  • blue 青

↑の例の場合、以下のような値を渡している。

  • alpha = 128
  • red = 51
  • green = 51
  • blue = 51

colors.xmlで定義する方法

app_name/app/src/main/res/values/colors.xml
<color name="example">#80333333</color>

2桁ごとに以下の4つの値を16進数(0〜FF)で指定する。

  • alpha 透過率
  • red 赤
  • green 緑
  • blue 青

↑の例の場合、以下のような値を定義している。

  • alpha = 80
  • red = 33
  • green = 33
  • blue = 33

実装の際に参考になったサイト

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0