zoukankan      html  css  js  c++  java
  • 对TextView设置drawable,用setCompoundDrawables方法实现

    在上一项目上需要对TextView在xml文件中设置的drawableLeft的图片进行更改,查询了资料好久也没有找到解决办法,如下代码所示:

    1 commentTV.setCompoundDrawables(drawable, null, null, null);

    后来又经过在stackoverflow,sourceforge等网站上进行询问,才发现是因为缺少了对drawable的边界进行处理,修改后的可起作用代码如下:

    1 Drawable drawable = getResources().getDrawable(
    2                         R.drawable.edit_icon);
    3 drawable.setBounds(0, 0, drawable.getMinimumWidth(),
    4                         drawable.getMinimumHeight());
    5 commentTV.setCompoundDrawables(drawable, null, null, null);

    解决了一个小问题,不敢独享喜悦,故发篇小博客来纪念一下,也希望能够帮到后来遇到相似问题的同行,使少走弯路~

    谢谢打赏!
    您的支持就是我的最大动力!


    支付宝

    微信


    Just remember: Half is worse than none at all.

    本文是由SilentKnight诚意发布, 欢迎转载! 但转载请注明出处: 【SilentKnight】
    如果觉得还有帮助的话,可以点一下右下角的【推荐】,希望能够持续的为大家带来更好的技术文章!
    想跟我一起进步么?那就【关注】我吧

    如果,想给予我更多的鼓励,求打

  • 相关阅读:
    Swift 构造与析构
    Swift 协议
    Swift 扩展
    Swift 多态
    Swift 继承
    Swift 封装
    Swift 方法
    Swift 属性
    Swift 对象
    Swift 类
  • 原文地址:https://www.cnblogs.com/littlepanpc/p/3469371.html
Copyright © 2011-2022 走看看