Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取Android Material TextInputLayout startIcon视图?_Android_Kotlin_Material Components Android - Fatal编程技术网

如何获取Android Material TextInputLayout startIcon视图?

如何获取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

有没有办法获取Android材质库
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

我的测试演示:


您始终可以自定义布局。请分享一些图片,以便我能理解你想要达到的目标。我添加了一个例子,你可以随时定制布局。请分享一些图片,以便我能理解你想要达到的目标。我补充了一个例子