Android TextView 程式碼中設定DrawableLeft 圖片
阿新 • • 發佈:2019-02-14
xml中的textView的drawableLeft是這樣設定的
使用程式碼為textview設定drawableLeft<TextView android:id="@ id/demoTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/drawable_left_icon" <span style="white-space:pre"> </span>android:text="你好" android:gravity="center_vertical" android:textSize="10dp" />
Drawable drawable = getResources().getDrawable(R.drawable.icon_sign_flashlight_closed);// 找到資源圖片 // 這一步必須要做,否則不會顯示。 drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());// 設定圖片寬高 tv_flashlight_top.setCompoundDrawables(drawable, null, null, null);// 設定到控制元件中