Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify tint as custom attribute on ImageView when using MotionLayout

How do I specify a tint color to an imageView as a custom attribute when using MotionLayout. Currently I can only specify a custom background color in my MotionScene xml file:

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:id="@+id/imageView"
        android:layout_width="180dp"
        android:layout_height="180dp"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent"
        motion:layout_constraintVertical_bias="0.75"
        motion:srcCompat="@drawable/ic_android_black_24dp" >
        <CustomAttribute
            motion:attributeName="backgroundColor"
            motion:customColorValue="#9999FF" />
    </Constraint>
</ConstraintSet>
like image 301
Ememobong AkpanEkpo Avatar asked Aug 06 '18 01:08

Ememobong AkpanEkpo


2 Answers

Note that you are using backgroundColor but the attribute is android:background. For tint you should write:

            <CustomAttribute
                motion:attributeName="ColorFilter"
                motion:customColorValue="#9999FF" />

As far as I know, the feature of CustomAttribute uses reflection and not the attributes from xml etc. Keep that in mind for all custom attributes.

like image 155
ylus Avatar answered Nov 04 '22 03:11

ylus


You can use ColorFilter.

<CustomAttribute
    motion:attributeName="colorFilter"
    motion:customColorValue="@color/your_tint_color" />
like image 9
Lin Lin Avatar answered Nov 04 '22 03:11

Lin Lin