关于android中的EditView,TextView的图片问题
16lz
2021-01-23
在开发中经常遇到再一个输入框中需要使用到图片的问题.
这里做一个备份
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.
更多相关文章
- android 手机管理软件 发布开源代码
- 实用代码3
- Android NDK 编译、使用动态库
- Android Studio - 第四十七期 毛玻璃效果以及动态生成二维码以及
- Android使用代码实现关机/重启
- 【知识点】android代码中设置margin
- Android蓝牙通信代码