0

Is there any possibility to draw a rectangle shape with any hex color with opacity for that color

for example blue_color_background.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid
        android:color="#29618E"/>
    <corners
        android:radius="@dimen/_10sdp"/>

</shape>

The above code is a normal rectangle shape with a radius of 10dp

But I want the given opacity for the shape without changing the hex code. And how to achieve this

3 Answers3

0

If you don't want to change a color, you can add android:alpha property to your View. For example:

<View
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/blue_color_backgroung"
    android:alpha="0.5"/>
Tiko
  • 851
  • 8
  • 15
0

The opacity attribute in android XML is alpha you can set alpha for a view in the range of 0.0 to 1.0 which 0.0 is fully transparent. just use like this :

android.alpha="0.7"
0
Drawable customeShape = 
getResources().getDrawable(R.drawable.custom_shape);

 // setting the opacity (alpha)

customeShape.setAlpha(10);

// setting the images on the ImageViews

image.setImageDrawable(customeShape);
Mayur W.
  • 1
  • 2