您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Android按钮上以编程方式设置drawableLeft?

如何在Android按钮上以编程方式设置drawableLeft?

你可以使用该setCompoundDrawables方法执行此操作。请参阅此处的示例。我在不使用的情况下使用了setBounds它,并且效果很好。你可以尝试任何一种方式。

更新:如果链接断开,请在此处复制代码

Drawable img = getContext().getResources().getDrawable(R.drawable.smiley);
img.setBounds(0, 0, 60, 60);
txtVw.setCompoundDrawables(img, null, null, null);

要么

Drawable img = getContext().getResources().getDrawable(R.drawable.smiley);
txtVw.setCompoundDrawablesWithIntrinsicBounds(img, null, null, null);

要么

txtVw.setCompoundDrawablesWithIntrinsicBounds(R.drawable.smiley, 0, 0, 0);
其他 2022/1/1 18:16:53 有460人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶