在开发中经常遇到再一个输入框中需要使用到图片的问题.
这里做一个备份
1.在XML中使用
android:drawableLeft="@drawable/icon"
2.代码中动态变化
Drawable drawable= getResources().getDrawable(R.drawable.drawable);
///!!!!!!!!!!!!!!!!!!!!!!!这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
editview.setCompoundDrawables(drawable,null,null,null);
或者直接使用
editview.setCompoundDrawablesWithIntrinsicBounds();
注意:代码中动态变化必须要设置setBounds,否则不会显示.或者使用setCompoundDrawablesWithIntrinsicBounds.
这里做一个备份
1.在XML中使用
android:drawableLeft="@drawable/icon"
2.代码中动态变化
Drawable drawable= getResources().getDrawable(R.drawable.drawable);
///!!!!!!!!!!!!!!!!!!!!!!!这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
editview.setCompoundDrawables(drawable,null,null,null);
或者直接使用
editview.setCompoundDrawablesWithIntrinsicBounds();
注意:代码中动态变化必须要设置setBounds,否则不会显示.或者使用setCompoundDrawablesWithIntrinsicBounds.