Add a drawable on textView during MotionScene

79 Views Asked by At

Is there a way do add a drawable (on the left) of a textView during a MotionScene?

I have try to use customAttribute (name "drawableLeft" & "drawableStart"), with customStringValue (my drawable) with no success... The drawable don't appear during the MotionScene.

Thanks you

Edit:

Thanks @BoredAndroidDeveloper for your tips This is my xml :

<androidx.constraintlayout.motion.widget.MotionLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/motion_layout"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:layoutDescription="@xml/filters_motion"
  android:paddingRight="4dp"
  android:paddingEnd="4dp"
  android:paddingStart="4dp"
  android:paddingLeft="4dp" >

  <androidx.appcompat.widget.AppCompatTextView
      android:id="@+id/filter"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/item_background"
      app:layout_constraintTop_toTopOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      android:textSize="14sp"
      android:fontFamily="@font/maven_pro_medium"
      android:textColor="@color/white"
      android:textAllCaps="false"
      android:gravity="center"
      android:paddingTop="7dp"
      android:paddingBottom="8dp"
      android:paddingRight="12dp"
      android:paddingLeft="12dp"
      android:paddingEnd="12dp"
      android:paddingStart="12dp"
      android:drawablePadding="8dp" />

</androidx.constraintlayout.motion.widget.Motion

"item_background" is a shape which is filled or empty, this one works :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:drawable="@drawable/background_filter_filled"
    android:state_activated="true" />
  <item
    android:drawable="@drawable/background_filter" />
</selector>

My MotionScene is like this :

<MotionScene
    xmlns:motion="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <Transition
        motion:constraintSetStart="@id/start"
        motion:constraintSetEnd="@+id/end"
        motion:motionInterpolator="easeInOut">
    </Transition>

    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@+id/filter_name" >
            <CustomAttribute
              motion:attributeName="textColor"
              motion:customColorValue="@color/blue" />
        </Constraint>
    </ConstraintSet>

    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@+id/filter_name" >
            <CustomAttribute
                motion:attributeName="textColor"
                motion:customColorValue="@color/white" />
        </Constraint>
    </ConstraintSet>
</MotionScene>

I have try this :

<CustomAttribute
  motion:attributeName="drawableLeft"
  motion:customStringValue="@null" /> (in start)
<CustomAttribute
  motion:attributeName="drawableLeft"
  motion:customStringValue="@drawable/ic_check" /> (in end)
0

There are 0 best solutions below