Assuming I have an ImageView defined as:
<ImageView
android:id="@+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/my_image_view_background"
/>
With my_image_view_background being:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<gradient
android:angle="45"
android:startColor="#555555"
android:endColor="#111111"
android:type="radial"
android:centerX="0.1"
android:centerY="0.1"
android:gradientRadius="70"
/>
<stroke
android:width="5dp"
android:color="#ff3300"
/>
</shape>
Is it possible to access the my_image_view_background drawable and change the colour of its stroke in code? Also, is it possible to do that based on the ‘state’ (pressed/selected/default)?
yes its possible
using GradientDrawable you can do it thru code.
link:
refer this site: