Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change TimePicker text color

Tags:

android

xml

I've been trying to change the textcolor of my timepicker. But I can't find where the parent style is located. I've tried both

<style name="MyTimePicker" parent="@android:style/Widget.Holo.TimePicker">
    <item name="android:textColor">@color/text</item>
</style>

and

<style name="MyTimePicker" parent="@android:style/Widget.TimePicker">
    <item name="android:textColor">@color/text</item>
</style>

My minSdkVersion is 15. My targetSdkVersion is 20. I have rebuilded and cleaned my project.
I think I've been through every similar question on SO and none of them really have provided a solution for me. The only answer that might work is using some sort of library, but I'm not a big fan of that solution. Is the path to the parent something different from what I'm using, because I'm pretty sure I should be able to access it somehow?

Edit
This is how the theme is applied;

<TimePicker
    style="@style/MyTimePicker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/timePicker"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true" />

On a note this is the error I receive (forgot to place it before):

Error:Error retrieving parent for item: No resource found that matches the given name '@android:style/Widget.Holo.TimePicker'.

Edit 2 A couple of the questions I've viewed to try to solve this:

  1. How can I override TimePicker to change text color - I think this question gets as close to an answer, but I'm not entirely sure what I need to do? Do I need to import the android TimePicker style into my project?
  2. https://stackoverflow.com/questions/24973586/set-textcolor-for-timepicker-in-customized-app-theme - No answer is given.
  3. How can i change the textcolor of my timepicker and datepicker? - Tried the 0 votes answer, but it didn't work.
  4. How to change the default color of DatePicker and TimePicker dialog in Android? - Again can't find the TimePicker in a similar way.
  5. Android - How do I change the textColor in a TimePicker? - Again, can't find the actual TimePicker parent.

These are probably the best questions/answers to my problem, but none of them help me. It would be nice to get a definitive answer on this.

like image 532
Bono Avatar asked Sep 24 '14 11:09

Bono


People also ask

How do I change the color of my text view?

There are two methods of changing the color of a TextView and the code for that has been given in both Java and Kotlin Programming Language for Android, so it can be done by directly adding a color attribute in the XML code or we can change it through the MainActivity File.

How do I change the color of my time picker?

Here's how you do it: Step 1: Inside the showDatePicker function, add the builder paramter. Step 2: Inside the builder parameter, return the Theme widget. Step 3: Inside the Theme widget, add the data property and define the new theme by specifying the colorScheme for the date picker dialog.


2 Answers

Not sure why you would need to dive into Java Reflection API for this. Its a simple styling matter. The attribute that you need to override is: textColorPrimary.

<style name="AppTheme" parent="@android:style/Theme.Holo.Light">
    ....
    <item name="android:textColorPrimary">#ff0000</item>
</style>

If you're using the TimePicker inside a Dialog, override android:textColorPrimary in the dialog's theme.

That's about it.

like image 84
Vikram Avatar answered Sep 21 '22 20:09

Vikram


@Vikram is right This is so simple.You can try this way

<style name="abirStyle" parent="@android:style/Theme.Holo.Light.Dialog.NoActionBar">
    <item name="android:textColor">@color/colorPrimary</item>
    <item name="android:background">@null</item>
    <item name="android:textColorPrimary">@color/colorPrimary</item>
</style>
like image 43
Muhaiminur Rahman Avatar answered Sep 21 '22 20:09

Muhaiminur Rahman