0

I have this @color selector: my_color.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:alpha="0.10" android:color="@color/og_ripple_base_dark" android:state_pressed="true"/>
  <item android:alpha="0.12" android:color="@color/og_ripple_base_dark" android:state_focused="true"/>
  <item android:alpha="0.04" android:color="@color/og_ripple_base_dark" android:state_hovered="true"/>
</selector>

I want to map it to a @drawable selector

but <solid> has no android:alpha

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true">
    <shape android:shape="oval">
      <solid android:alpha="0.10" android:color="@color/og_ripple_base_light"/>
    </shape>
  </item>
  <item android:state_focused="true">
    <shape android:shape="oval">
      <solid android:alpha="0.12" android:color="@color/og_ripple_base_light"/>
    </shape>
  </item>
  <item android:state_hovered="true">
    <shape android:shape="oval">
      <item android:alpha="0.04" android:color="@color/og_ripple_base_light"/>
    </shape>
  </item>
</selector>

So I have tried this as well, but the alpha channel is ignored when i run on emulator:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true">
    <shape android:shape="oval">
      <solid android:color="@color/my_color"/>
    </shape>
  </item>
</selector>

How can I specify in xml a base color + alpha and set this value to my s tags?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471
  • You can try making a alpha value with the color. See https://stackoverflow.com/a/16890937/3964537 – Megaetron Jun 04 '19 at 22:04
  • @Megaetron yes, but i would prefer to use strings instead of assembling color codes. possible? – Elad Benda Jun 04 '19 at 22:27
  • As far as I know, there's no other way than using color codes. Except you give an alpha value the view which receives the shape. – Megaetron Jun 04 '19 at 22:52

0 Answers0