好用的 Android getDrawable過時的替代方法
之前程式碼中獲取Drawable都是使用如下方法:
Drawable TopDrawableOne = getResources().getDrawable(R.drawable.icon_test);
但是此方法過時,不推薦使用,那麼肯定是有其他替代方法的,經過查詢,很多網友都是推薦使用
Drawable getDrawable(int id, Resources.Theme theme), 第二個引數@theme可以為空值.或Context.getDrawable(int)
但是感覺此方法不是很好用就在此查詢有沒有其他好用的方法,最後找到
Drawable TopDrawableOne = ContextCompat.getDrawable(context,R.drawable.icon_test);
這種方式,看著舒服,也是谷歌推薦使用的。
相關推薦
好用的 Android getDrawable過時的替代方法
之前程式碼中獲取Drawable都是使用如下方法: Drawable TopDrawableOne = getResources().getDrawable(R.drawable.icon_test
Android getResources().getColor() 過時 替代方法
在Java程式碼中設定控制元件的Color時,用getResources().getColor()出現如下提示: getColor方法在Android 6.0即API 23中 已經過時,替代方法為
Android-6.0-23的getColor()過時替代方法
getColor方法在6.0中已經過時: @[email protected] getColor(@ColorResint id)throwsNotFoundException{retu
Android getDrawable過時問題處理
Android獲取Drawable時通常使用方法 getResources().getDrawable(resId); 此方法提示過時,使用如下替代方案: if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT
Android中getDrawable和getColor過時的替代方法
this logs con 知識 log launcher 16px ase spa 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 前言 Android SDK 升級到 23 之後,getDrawable和getColor方法提示過時。 解決方案 getRe
Android中ViewPager的setOnPageChangeListener方法過時的替代方法
android.support.v4.view包裡的ViewPager可用於實現輪播圖。我們可以用ViewPager.setOnPageChangeListener(ViewPager.OnPageChangeListener)方法監聽其滑動事件,ViewPager.OnPageChangeLi
android過時方法的替代方法
1:getResource.getColor(R.color.color_name)----------------------------Android SDK 升級到 23 之後,
Android中getColor方法過時的替代方法
在Java程式碼中設定控制元件的Color時,通常這樣寫:txtLabel.setTextColor(getResources().getColor(R.color.black));但是getColor
給Android元件新增事件一個很好用的方法
在這裡想和大家分享一下很好用的新增事件方法,特別是在處理ListView裡的Item事件的時候,很方便。 首先,在XML里布局的時候,新增這樣一個屬性: android:onClick="CallOnclick",比如你要對Button新增事件, <Butto
Android開發中Html.fromHtml(String source)方法過時的替代方法
前言 我們在開發中難免會遇到一個字串中有不同顏色的字型或者有不同大小的字型這樣的需求,所以可能會用到Html.fromHtml(String source) ,程式碼如下: String str2 = "今天<font color='#FF0000'&
getDrawable()方法過時 替代
context.getResources().getDrawable(R.mipmap.icon_my); 官方推薦呼叫 context.getResources().g
【Android】一個好用的sharedpreferences存儲類方法
true spa Edito roi util https pack fig rda 其實我也不知道sharedpreferences究竟安全不安全,畢竟是android中最簡單的存儲機制。 如果你手機root了的話,使用MT管理器到data/data/包名/shared
Python有哪些好用的語言翻譯方法
size webkit ted mage clas lan 網上 eba splay 最近有個需求,要將幾萬條數據從日語翻譯成中文。因為數據的獲取和處理用的是python代碼,所以想先嘗試翻譯部分也用python實現。 目前網上查到的翻譯方法有百度、有道以及谷歌翻譯,下
水平垂直居中的——萬能好用方法
width logs style round alt src ati right circle 一、absolute方法 HTML代碼如下: <body> <div id="box"> <div cla
【Android個人理解(八)】跨應用調用不同組件的方法
返回 使用 turn 數字 現實 rpc 文件夾 cas rgb 如果情景: 創建兩個應用appA和appB,appA包括一個Service,此Service有一個堵塞方法每隔10秒鐘產生一個隨機數字,例如以下: public int getRandom
Unity3D調用android方法(非插件方式)
pri hone hand 沒有 run project ets color androi 關於Unity3Dproject與androidproject的轉換與合並,請參考我的另外一篇博客。假設你對Unity3Dproject增加到androidproject的過
調用android的getColor()方法出現 java.lang.NoSuchMethodError: android.content.res.Resources.getColor
sdn targe drawable ava source 添加 andro content 鏈接 1.java.lang.NoSuchMethodError: android.content.res.Resources.getDrawable/getColor或者 jav
Android好用的外掛
1.Android Resource Usage Count 顧名思義,這是一個可以顯示 Android 資源使用次數的外掛,產品或者設計經常需要改動一個 string 或者 color,在改動之前你得先手動在那個資原始檔上右鍵 - Find Usage , 引用次數為 1 就直接改動
【開源框架】Android 好用的框架與UI效果demo收集,歡迎各位大俠補充
索引貼 持續更新 github開源專案收集貼 Android 初級到高階開發學習中的日常積累收集 目錄 UI效果與處理 Ui繫結註解 二維碼 Android動畫 Android圖表 文字輸入框 選擇列表
去除List集合中的重複值(四種好用的方法)(基本資料型別可用)
最近專案中需要對list集合中的重複值進行處理,大部分是採用兩種方法,一種是用遍歷list集合判斷後賦給另一個list集合,一種是用賦給set集合再返回給list集合。 但是賦給set集合後,由於set集合是無序的,原先的順序就打亂了。所以我又想著能不能用set的特性進行去重又不打亂順序