最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android  setButtonDrawable()的兼容問題解決辦法

 更新時間:2017年03月13日 09:50:33   作者:ihrthk  
這篇文章主要介紹了Android setButtonDrawable()的兼容問題解決辦法的相關資料,需要的朋友可以參考下

Android  setButtonDrawable()的兼容問題解決辦法

setButtonDrawable()的兼容問題

API16實現(xiàn)

 /**
  * Set the background to a given Drawable, identified by its resource id.
  *
  * @param resid the resource id of the drawable to use as the background 
  */
 public void setButtonDrawable(int resid) {
  if (resid != 0 && resid == mButtonResource) {
   return;
  }

  mButtonResource = resid;

  Drawable d = null;
  if (mButtonResource != 0) {
   d = getResources().getDrawable(mButtonResource);
  }
  setButtonDrawable(d);
 }

 /**
  * Set the background to a given Drawable
  *
  * @param d The Drawable to use as the background
  */
 public void setButtonDrawable(Drawable d) {
  if (d != null) {
   if (mButtonDrawable != null) {
    mButtonDrawable.setCallback(null);
    unscheduleDrawable(mButtonDrawable);
   }
   d.setCallback(this);
   d.setState(getDrawableState());
   d.setVisible(getVisibility() == VISIBLE, false);
   mButtonDrawable = d;
   mButtonDrawable.setState(null);
   setMinHeight(mButtonDrawable.getIntrinsicHeight());
  }

  refreshDrawableState();
 }

API23實現(xiàn)

 /**
  * Sets a drawable as the compound button image given its resource
  * identifier.
  *
  * @param resId the resource identifier of the drawable
  * @attr ref android.R.styleable#CompoundButton_button
  */
 public void setButtonDrawable(@DrawableRes int resId) {
  final Drawable d;
  if (resId != 0) {
   d = getContext().getDrawable(resId);
  } else {
   d = null;
  }
  setButtonDrawable(d);
 }

 /**
  * Sets a drawable as the compound button image.
  *
  * @param drawable the drawable to set
  * @attr ref android.R.styleable#CompoundButton_button
  */
 @Nullable
 public void setButtonDrawable(@Nullable Drawable drawable) {
  if (mButtonDrawable != drawable) {
   if (mButtonDrawable != null) {
    mButtonDrawable.setCallback(null);
    unscheduleDrawable(mButtonDrawable);
   }

   mButtonDrawable = drawable;

   if (drawable != null) {
    drawable.setCallback(this);
    drawable.setLayoutDirection(getLayoutDirection());
    if (drawable.isStateful()) {
     drawable.setState(getDrawableState());
    }
    drawable.setVisible(getVisibility() == VISIBLE, false);
    setMinHeight(drawable.getIntrinsicHeight());
    applyButtonTint();
   }
  }
 }

結論

RadioButton和CheckBox都是Android app中常用的Widget,它們派生于CompoundButton,允許使用者自行設置背景和按鈕的樣式,不過,有時我們僅希望簡單的設置一個有狀態(tài)的背景,并隱藏其默認樣式??墒牵斘覀冋{用setButtonDrawable(null)或setButtonDrawable(0)時,卻發(fā)現(xiàn)完全沒有效果。原來,CompoundButton的setButtonDrawable的代碼實現(xiàn)中屏蔽了null或resid為0的Drawable,迫使我們必須傳入有效的Drawable對象。

這時候,透明顏色就可以派上用場了:

button.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT));

參考:

隱藏RadioButton, CheckBox圖片 setButtonDrawable:

RadioButton和CheckBox都是Android app中常用的Widget,它們派生于CompoundButton,允許使用者自行設置背景和按鈕的樣式,不過,有時我們僅希望簡單的設置一個有狀態(tài)的背景,并隱藏其默認樣式。可是,當我們調用setButtonDrawable(null)或setButtonDrawable(0)時,卻發(fā)現(xiàn)完全沒有效果。原來,CompoundButton的setButtonDrawable的代碼實現(xiàn)中屏蔽了null或resid為0的Drawable,迫使我們必須傳入有效的Drawable對象。

這時候,透明顏色就可以派上用場了:

button.setButtonDrawable(new ColorDrawable(Color.TRANSPARENT)); 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關文章

  • 解析android中系統(tǒng)日期時間的獲取

    解析android中系統(tǒng)日期時間的獲取

    本篇文章是對在android中,如何系統(tǒng)日期時間獲取的方法進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • Kotlin fun函數使用方法

    Kotlin fun函數使用方法

    函數是執(zhí)行特定任務的一組相互關聯(lián)的代碼塊。函數用于將程序分解為不同的子模塊。它使代碼可重用,并使程序更易于管理,這篇文章主要介紹了Kotlin fun函數使用方法
    2022-12-12
  • Android Touch事件分發(fā)過程詳解

    Android Touch事件分發(fā)過程詳解

    這篇文章主要介紹了Android Touch事件分發(fā)過程,詳細描述了Android Touch事件的主要處理流程,有助于深入理解Android程序設計,需要的朋友可以參考下
    2014-09-09
  • 詳解Android Bitmap的常用壓縮方式

    詳解Android Bitmap的常用壓縮方式

    這篇文章主要介紹了詳解Android Bitmap的常用壓縮方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-01-01
  • Android控件之GridView用法實例分析

    Android控件之GridView用法實例分析

    這篇文章主要介紹了Android控件之GridView用法,通過繪制九宮格的實例形式分析了GridView可滾動網格的實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • 淺析Android中build.gradle的實用技巧

    淺析Android中build.gradle的實用技巧

    這篇文章主要介紹了淺析Android中build.gradle的實用技巧,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-03-03
  • Android 使用PDF.js瀏覽pdf的方法示例

    Android 使用PDF.js瀏覽pdf的方法示例

    這篇文章主要介紹了Android 使用PDF.js瀏覽pdf的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • 詳解Android Webview加載網頁時發(fā)送HTTP頭信息

    詳解Android Webview加載網頁時發(fā)送HTTP頭信息

    這篇文章主要介紹了詳解Android Webview加載網頁時發(fā)送HTTP頭信息的相關資料,需要的朋友可以參考下
    2017-05-05
  • 詳解Android Studio中Git的配置及協(xié)同開發(fā)

    詳解Android Studio中Git的配置及協(xié)同開發(fā)

    這篇文章主要介紹了詳解Android Studio中Git的配置及協(xié)同開發(fā),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-03-03
  • App中如何獲取gradle的配置信息

    App中如何獲取gradle的配置信息

    這篇文章主要給大家介紹了關于App中如何獲取gradle的配置信息的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-02-02

最新評論

固始县| 巩留县| 醴陵市| 孝感市| 长治县| 武宣县| 阳东县| 姚安县| 南和县| 连江县| 田阳县| 新竹县| 剑阁县| 平顶山市| 临西县| 闸北区| 江陵县| 孝义市| 新昌县| 平和县| 缙云县| 上高县| 泰宁县| 全椒县| 大丰市| 太原市| 循化| 梧州市| 奉节县| 老河口市| 乐陵市| 辽中县| 洛浦县| 治县。| 贺兰县| 宁远县| 郎溪县| 托里县| 新巴尔虎左旗| 连云港市| 丹寨县|