如何在Android Edittext上以编程方式设置drawableRight? [英] How to programmatically set drawableRight on Android Edittext?

查看:152
本文介绍了如何在Android Edittext上以编程方式设置drawableRight?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在XML中设置drawableRight的知识.但我需要以编程方式执行此操作,因为它会根据某些条件进行更改.

I know about set drawableRight in XML. but i required to do it programmatically because it is change as per some condition.

推荐答案

您可以使用以下功能:

editText.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.drawableRight, 0);

或(如果您想传递可绘制对象本身而不是其ID)

or (if you want to pass the drawable itself instead of its ID)

editText.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(context,R.drawable.drawableRight), null)

与可绘制位置相对应的参数顺序为:左,上,右,下

The order of params corresponding to the drawable location is: left, top, right, bottom

这篇关于如何在Android Edittext上以编程方式设置drawableRight?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆