Android在代码中设置drawableLeft(Right/Top/Bottom)
生活随笔
收集整理的這篇文章主要介紹了
Android在代码中设置drawableLeft(Right/Top/Bottom)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
根據業務的需要,要在代碼中設置控件的drawableLeft,drawableRight,drawableTop,drawableBottom屬性。
我們知道在xml中設置的方法為:
android:drawableLeft="@drawable/xxxxx"但是在代碼中并沒有相關的setDrawableLeft等方法。怎么辦呢?
別擔心,api為我們提供了一個setCompoundDrawables(left,top,right,bottom);方法,供開發人員設置相應的邊界圖片。
操作方法十分簡單,如下代碼所示:
// 使用代碼設置drawableleftDrawable drawable = getResources().getDrawable(R.drawable.ic_qaa_top_icon);// 這一步必須要做,否則不會顯示。drawable.setBounds(0, 0, drawable.getMinimumWidth(),drawable.getMinimumHeight());Button.setCompoundDrawables(null, null, drawable, null);總結
以上是生活随笔為你收集整理的Android在代码中设置drawableLeft(Right/Top/Bottom)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 异形:隔离 全关卡图文攻略
- 下一篇: 《王者荣耀》云缨铭文出装推荐 云缨玩法攻