TextView的xmlandroid
- <TextView
- android:id="@+id/textciew1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="#000"
- android:drawableRight="@drawable/button_nav_down"
- android:gravity="center_vertical"
- android:paddingLeft="16dp"
- android:paddingRight="16dp"
- android:text="展開"
- android:textColor="#fff"
- />
在代碼中若是要修改drawableRight設置的圖片能夠使用.net
setCompoundDrawables(Drawable left,Drawable top,Drawable right,Drawable bottom)xml
Drawable能夠經過 Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);獲得對象
可是API提示,setCompoundDrawables() 調用的時候,Drawable對象必須調用setBounds(int left, int top, int right, int bottom)方法,因而咱們加一行代碼就能夠了blog
- nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
代碼合在一塊兒是這樣的:圖片
- Drawable nav_up=getResources().getDrawable(R.drawable.button_nav_up);
- nav_up.setBounds(0, 0, nav_up.getMinimumWidth(), nav_up.getMinimumHeight());
- textview1.setCompoundDrawables(null, null, nav_up, null);