对于TextView或者EditText动态设置drawableLeft,drawableRight,drawableTop,drawableBottom,drawableStart,drawableEnd的方法总结
Android中提供了许多动态设置的方法
但是用中容易造成的问题是,我们往往只调用了如上的一些方法,但并没有将Drawable的Bounds设置为特定的数据,导致这些图片无法显示,因此,做如下操作即可
设置右方向上的图片
Drawable drawable = getResources().getDrawable(R.drawable.hotel_search);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
selectCityTv.setCompoundDrawables(null, null, drawable, null);
或者我们可以使用另外一些方法
selectCityTv.setCompoundDrawablesWithIntrinsicBounds( Drawable left, Drawable top,Drawable right,Drawable bottom)
——-这里就不再试验了——–