mercredi 29 juin 2016

How to change the default color scheme timepicker dialog fragment?

I am trying to change the default color the timepicker dialog fragment. and right now i have no idea as to what im supposed to be doing.

this what i have managed to set my theme to (withouth the actionBar):

enter image description here

but this is the dialog i get: enter image description here

this is my xml style file:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light">
        <item name="colorPrimary">@color/color_accent</item>
        <item name="colorPrimaryDark">@color/color_secondary</item>
        <item name="colorAccent">@color/color_accent</item>
        <item name="android:statusBarColor">@color/color_primary</item>
    </style>
</resources>

My colors file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="flat_text">#f14268</color>
    <color name="background_flatbtn">#fff</color>
    <color name="color_accent">#f14268</color>
    <color name="color_primary">#d83b5d</color>
    <color name="color_secondary">#d83b5d</color>
</resources>

mytimepicker fragment:

public class DialogHandler extends DialogFragment
        implements TimePickerDialog.OnTimeSetListener {
    Context context;

    public DialogHandler(Context context){
        this.context=context;

    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current time as the default values for the picker
        final Calendar c = Calendar.getInstance();
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        TimePickerDialog dialog= new TimePickerDialog(new ContextThemeWrapper(getActivity(),R.style.AppTheme), this, hour, minute, DateFormat.is24HourFormat(getActivity()));
        // Create a new instance of TimePickerDialog and return it
        return dialog;
    }

    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
        // Do something with the time chosen by the user
        Toast.makeText(context, "your time is selected",Toast.LENGTH_LONG).show();
    }
}

my dialogue call:

DialogHandler newFragment = new DialogHandler(getApplicationContext());
        newFragment.show(getSupportFragmentManager() , "time_Picker");

Please help me . Thanks in Advance :)

Aucun commentaire:

Enregistrer un commentaire