日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Android在代码中设置drawableLeft(Right/Top/Bottom)

發布時間:2023/12/13 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。