android - 以编程方式更改按钮的 drawableLeft

标签 android image button textview drawable

我正在使用一个按钮

<Button
        android:id="@+id/zoom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/trans"
        android:drawableLeft="@drawable/left_img"
        android:fontFamily="arial"
        android:text="My Name is "
        android:textSize="50sp" />

并使用 :

更改其文本颜色
zoom.setTextColor(Color.parseColor("voilet"));

但无法理解如何更改其图像??

最佳答案

试试这个:

int imgResource = R.drawable.left_img;
button.setCompoundDrawablesWithIntrinsicBounds(imgResource, 0, 0, 0);

Reference

关于android - 以编程方式更改按钮的 drawableLeft,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18278003/

相关文章:

android - 屏幕外的 Leadbolt 横幅

android - 固定无法找到明确的 Activity 类恼人的错误

c# - Azure 数据库和照片

javascript - 在javascript中定向后 Canvas 将图像裁剪为正方形

android - 从 SQLite DB 中获取图像并在 WebView 中显示它们的最佳方法 (Android)

html - 如何用图像填充提交按钮?

android - PreferenceScreen 的状态列表?

android - IntentService 在 Android 4.2 (Jelly Bean) 上有问题吗?

Android 状态栏通知 - 有什么方法可以在状态栏上弹出通知( toast )?

html - span inside anchor 不起作用,有什么想法吗?