Issue
Is there a way to get a reference to the Android Material Library TextInputLayout
startIcon
's View
? TextInputLayout.startIconDrawable
only gets the Drawable
, not the View
. I'm trying to animate this View
, so I need a reference. Here's an example below, I would like a View reference to the heart icon.
Solution
You can access the startIcon
of the TextInputLayout
using its resource identifier name to get the resource integer id using getIdentifer()
of the Resources
class.
The identifier name of the TextInputLayout
is text_input_start_icon
To get the id of startIcon
:
Kotlin
val startIconViewId = resources.getIdentifier("text_input_start_icon", "id", packageName)
Java
int startIconViewId = getResources().getIdentifier("text_input_start_icon", "id", getPackageName());
And to get the view itself (which is CheckableImageButton
) to make your animation:
Kotlin
val textInputLayout = findViewById<TextInputLayout>(R.id.my_text_input_layout)
val startIcon: CheckableImageButton = textInputLayout.findViewById(startIconViewId)
Java
TextInputLayout textInputLayout = findViewById(R.id.my_text_input_layout);
CheckableImageButton startIcon = textInputLayout.findViewById(startIconViewId);
Note: To use this procedure you must set app:startIconDrawable
in TextInputLayout
in your layout.
Demo of my test:
Answered By - Zain
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.