如何获取Android Material TextInputLayout startIcon视图?
有没有办法获取Android材质库如何获取Android Material TextInputLayout startIcon视图?,android,kotlin,material-components-android,Android,Kotlin,Material Components Android,有没有办法获取Android材质库TextInputLayoutstartIcon的视图的引用TextInputLayout.startIconDrawable仅获取可绘制的,而不是视图。我正在尝试设置这个视图的动画,所以我需要一个参考。下面是一个例子,我想要一个心脏图标的视图引用 您可以使用TextInputLayout的资源标识符名称访问startIcon,以使用类的名称获取资源整数id TextInputLayout的标识符名称是text\u input\u start\u图标 要获取st
TextInputLayout
startIcon
的视图的引用TextInputLayout.startIconDrawable
仅获取可绘制的
,而不是视图
。我正在尝试设置这个视图的动画,所以我需要一个参考。下面是一个例子,我想要一个心脏图标的视图引用
您可以使用TextInputLayout
的资源标识符名称访问startIcon
,以使用类的名称获取资源整数id
TextInputLayout
的标识符名称是text\u input\u start\u图标
要获取startIcon的id,请执行以下操作:
Kotlin
val startIconViewId = resources.getIdentifier("text_input_start_icon", "id", packageName)
val textInputLayout = findViewById<TextInputLayout>(R.id.my_text_input_layout)
val startIcon: CheckableImageButton = textInputLayout.findViewById(startIconViewId)
Java
int startIconViewId = getResources().getIdentifier("text_input_start_icon", "id", getPackageName());
TextInputLayout textInputLayout = findViewById(R.id.my_text_input_layout);
CheckableImageButton startIcon = textInputLayout.findViewById(startIconViewId);
要获取视图本身(即制作动画),请执行以下操作:
Kotlin
val startIconViewId = resources.getIdentifier("text_input_start_icon", "id", packageName)
val textInputLayout = findViewById<TextInputLayout>(R.id.my_text_input_layout)
val startIcon: CheckableImageButton = textInputLayout.findViewById(startIconViewId)
注意:要使用此过程,您必须在布局中的TextInputLayout
中设置app:startIconDrawable
我的测试演示:
您可以使用TextInputLayout
的资源标识符名称访问startIcon
,以使用类的名称获取资源整数id
TextInputLayout
的标识符名称是text\u input\u start\u图标
要获取startIcon的id,请执行以下操作:
Kotlin
val startIconViewId = resources.getIdentifier("text_input_start_icon", "id", packageName)
val textInputLayout = findViewById<TextInputLayout>(R.id.my_text_input_layout)
val startIcon: CheckableImageButton = textInputLayout.findViewById(startIconViewId)
Java
int startIconViewId = getResources().getIdentifier("text_input_start_icon", "id", getPackageName());
TextInputLayout textInputLayout = findViewById(R.id.my_text_input_layout);
CheckableImageButton startIcon = textInputLayout.findViewById(startIconViewId);
要获取视图本身(即制作动画),请执行以下操作:
Kotlin
val startIconViewId = resources.getIdentifier("text_input_start_icon", "id", packageName)
val textInputLayout = findViewById<TextInputLayout>(R.id.my_text_input_layout)
val startIcon: CheckableImageButton = textInputLayout.findViewById(startIconViewId)
注意:要使用此过程,您必须在布局中的TextInputLayout
中设置app:startIconDrawable
我的测试演示:
您始终可以自定义布局。请分享一些图片,以便我能理解你想要达到的目标。我添加了一个例子,你可以随时定制布局。请分享一些图片,以便我能理解你想要达到的目标。我补充了一个例子