2017-01-09 326 views

回答

-1

由於TextView的allCaps變量是本地包,因此您將無法輕鬆訪問它。如果這不是用於單元測試,那麼我會建議調查using reflection

如果您試圖通過單元測試來驗證,那麼您可以使用像PowerMock這樣的庫來使用反射來爲您獲取它。該代碼是這樣的:

boolean allCaps = Whitebox.getInternalState(textView, "allCaps"); 
+1

這並不適用於我,因爲allCaps不再是私人領域(不在Android奧利奧)。在這裏你可以修復它我發現你可以檢查它: textView.getTransformationMethod()!= null && textView.getTransformationMethod()。getClass()。getSimpleName() .equals(「AllCapsTransformationMethod」) – mennovogel

相關問題