Override NumberPicker styling

2.6k views Asked by At

Given an application which is themed via AppCompat (@style/Theme.AppCompat) and a layout using the framework's NumberPicker, is there a way to change its selectionDividersDistance[1]? Is this override even possible via XML, this is, without resorting to java reflection for example?

[1] selectionDividersDistance's styleable declaration)

2

There are 2 answers

2
Pedro Lopes On

Answering my own question: it is not possible to change selectionDividersDistance, when using the framework's NumberPicker, solely by using XML to override it, since the attribute is not declared publicly by the Android framework, as seen here.

Here is a bit more context about how public attributes work, and a thorough explanation by Edward Falk about how resources are mapped

1
Athul On

You can use this library for doing it https://github.com/SimonVT/android-numberpicker. instead of styling and for styling

Override default NumberPicker style via activity theme:

<style name="AppTheme" parent="@style/Holo.Theme">
  <item name="numberPickerStyle">@style/CustomNPStyle</item>
</style>
<style name="CustomNPStyle" parent="@style/Holo.NumberPicker">
  <item name="selectionDivider">@drawable/custom_np_sd</item>
</style>

And apply @style/AppTheme as activity theme.