0

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)

Pedro Lopes
  • 2,833
  • 1
  • 30
  • 36

2 Answers2

0

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.

Athul
  • 801
  • 7
  • 16
  • Thank for your reply Athul! I've eventually found that it is not possible to override the framework's NumberPicker `selectionDividersDistance` via XML, and answered my own question detailing that. The way the question was phrased, it could be tackled in either of our angles, so I'll leave as it is and not mark any as the definite correct answer, since they both complement each other. Cheers! – Pedro Lopes Dec 23 '16 at 00:40
0

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

Community
  • 1
  • 1
Pedro Lopes
  • 2,833
  • 1
  • 30
  • 36
  • Thanks for the refrence of Android framework. I just checked that and noticed there are 3 items defined for NumberPicker on lines 2713,2722 and 2723 (you can search `numberPicker` in that page easily). So, they might be added after your answer. Thanks. – Hesam Apr 11 '17 at 19:20
  • 1
    ah, it requires minimum Android level of 24 :( – Hesam Apr 11 '17 at 19:27