Stop ToggleButton text Capitalization at API 10

574 Views Asked by At

I want to stop my ToggleButton's text from being capitalized at API 10.

I know I can use setAllCap(false) to stop the Cap lock of Toggle Button, but how can I do the same at API level 10, since setAllCap(false) is only supported at API level 14, which is the Ice cream sandwich.

ps. In case someone wondering why am I doing this. (I know I am suppose to ask only one question, but this may help someone else with other problems)

I am trying to mimic tabs inside fragment by using a TableLayout with first row as toggle buttons, and changes the second row upon toggle those buttons. (FragmentTabHost is just problematic at the moment I think and is way too complicated for my use case). Everything works except the button text is always in upper case.

2

There are 2 best solutions below

1
On

You can call ToggleButton.setTextOn() and ToggleButton.setTextOff() and supply your own string. From what I can see from the implementation of ToggleButton, it does not auto capitalize strings set this way.

1
On

I'm not sure if you are using latest support library. You can take AllCapsTransformationMethodCompat.java and apply setAllCaps(false) like this:

AllCapsTransformationMethodCompat.setAllCaps(textViewInstance, true); - to capitalize all

AllCapsTransformationMethodCompat.setAllCaps(textViewInstance, text, false); - to preserve original text

In the 21.0+ support library there is exactly same backport of this MethodTransformation