Given a TextView, is there a way to tell if android:textAllCaps="true"
has been set in the XML?
Asked
Active
Viewed 547 times
0

loadedion
- 2,217
- 19
- 41
-
1This answer might help: http://stackoverflow.com/a/8038712/1245894 – Distwo Jan 09 '17 at 22:00
-
Thanks, the main issue I see with this is that `R.styleable.TextAppearance_textAllCaps` is a private style attribute, currently looking into accessing it – loadedion Jan 09 '17 at 22:22
1 Answers
-1
Since the TextView's allCaps
variable is package local you won't be able to access it easily. If this isn't for unit testing then I would suggest looking into using reflection.
If you are trying to verify this through unit testing then you can use a library like PowerMock to use reflection to get it for you. The code would look like this:
boolean allCaps = Whitebox.getInternalState(textView, "allCaps");
-
1This didn't work for me since allCaps is not a private field anymore (not on Android Oreo). Here you can fix it with I figured out you can check it with: textView.getTransformationMethod() != null && textView.getTransformationMethod().getClass().getSimpleName() .equals("AllCapsTransformationMethod") – mennovogel Jan 16 '18 at 10:46