sdk更新到Android 5.0後消失了方法TextView.getTextColor(Context context, TypedArray typedArray, int defStyle)
。
我對此自定義TextView使用了此方法(用於從xml定義的int colorId
)。
那麼如何從xml中確定int color id
?新的Android 5.0中消失了TextView.getTextColor(Context context,TypedArray typedArray,int defStyle)方法嗎?
3
A
回答
1
已確實刪除,你可以在API DIFF看到: https://developer.android.com/sdk/api_diff/21/changes.html
,您仍然可以使用這個變體:
2
這裏是獲取顏色TextView的一個示例代碼:
TextView tv = (TextView) findViewById(R.id.yourComponentId);
int tv_color = tv.getTextColors().getDefaultColor();
或者你也可以得到像這樣的正常文本的顏色:
TextView tv = (TextView) findViewById(R.id.yourComponentId);
int tv_color = tv.getCurrentTextColor();
在使用的第一個例子的情況下,也可以使用
TextView tv = (TextView) findViewById(R.id.yourComponentId);
ColorStateList colorStateList = tv.getTextColors();
int tv_color colorStateList.getColorForState(states, failColor);
希望這有助於獲得各種狀態的顏色。
相關問題
- 1. 如何轉換INT []以typedarray的Android
- 2. TypedArray中recycle()方法的用法
- 3. TypedArray無法正常工作
- 4. Javascript TypedArray性能
- 5. AppEventsLogger.deactivateApp(Context context)已棄用
- 6. Android ORMLite without context
- 7. Android Context Weak Reference
- 8. 使用Javascript - 從TypedArray在JSON
- 9. Android Activity Context is Null
- 10. Android從TypedArray獲取字符串數組
- 11. android中的'Context'是什麼?
- 12. 爲什麼要回收TypedArray?
- 13. 切片的JavaScript TypedArray多次
- 14. Kleisli [Future,Context,\ /] to Kleisli [EitherT,Context,...]
- 15. 確定範圍TypedArray項
- 16. 在android中使用Context更高效嗎?
- 17. android - context null while AsyncTask
- 18. 從typedarray獲取資源ID
- 19. 的Android defstyle參數
- 20. 如何在XML TypedArray中存儲drawable的int ID
- 21. 更有效的方法將重複序列複製到TypedArray中?
- 22. 方法getColor(Context,int)在Facebook sdk中未定義
- 23. 如何使用Context類android
- 24. Android 4.1上的KeyChain.getPrivateKey(Context,String)?
- 25. private [context]
- 26. TypedArray的Android無法獲得應有的價值
- 27. javax.faces。的context-param
- 28. 將可繪製圖像傳遞給Android中的TypedArray
- 29. Singleton和Context
- 30. git log「--function-context」
是公開的嗎? – Blackbelt 2014-10-22 08:43:30
@blackbelt是) – 2014-10-22 08:51:03
對於任何好奇的人,這個方法被刪除,因爲android.R.styleable既不公開也不穩定。因此,將TypedArray傳遞到任何框架視圖是不安全的,因爲數組索引不會與內部使用的android.R.styleable數組相匹配。這會以難以調試的方式破壞您的應用程序,因此我們刪除了所有這些方法。 – alanv 2014-10-22 23:47:57