badoualy / datepicker-timeline

An infinite scrolling timeline to pick a date
MIT License
464 stars 71 forks source link

Foreground color disappears when I add to an AlertDialog. #37

Open brightak opened 3 years ago

brightak commented 3 years ago

Hello,

When I put the datepicker in an AlertDialog, the forecolor disappears, as follows:

Set Body Weight

Here's some code: `

    btn.setOnClickListener(v -> {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.CustomAlertDialog);

        LayoutInflater inflater1 = getLayoutInflater();
        View dlgWeights = inflater1.inflate(R.layout.weights_dialog,null);

        builder.setTitle("Set Body Weight");

        builder.setView(dlgWeights);

        tvWeights = dlgWeights.findViewById(R.id.tvWeights);

        tvWeights.setText(spnWeights.getSelectedItemPosition() == 0 ? getString(R.string.lbs) : getString(R.string.kilos));

        npWeight = dlgWeights.findViewById(R.id.npWeight);

        Log.i("ProfileDialog", "Launching DatePickerTimeline");
        final DatePickerTimeline timeline = dlgWeights.findViewById(R.id.datePickerTimeLine);

        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        timeline.setOnDateSelectedListener((year, month, day, index) -> {
            Calendar date = Calendar.getInstance();
            date.set(year, month, day);
            refreshWeight(sdf.format(date.getTime()));
        });

        Calendar current = Calendar.getInstance();

        timeline.setSelectedDate(current.get(Calendar.YEAR), current.get(Calendar.MONTH), current.get(Calendar.DATE));

        refreshWeight(sdf.format(current.getTime()));

        builder.setPositiveButton(getString(R.string.OK), (dialog, which) -> {
            Calendar d = Calendar.getInstance();
            d.set(timeline.getSelectedYear(), timeline.getSelectedMonth(), timeline.getSelectedDay(), 0, 0, 0);
            ((ExerciseActivity) getActivity()).exerciseViewModel.ensureWeight(npWeight.getValue(), (int) (d.getTimeInMillis() / 1000L));
            refreshBodyWeight();
            dialog.dismiss();
        });

        builder.setNegativeButton(getString(R.string.Cancel), (dialog, which) -> dialog.dismiss());

        final AlertDialog dialog = builder.create();

        dialog.show();

    });`

R.layout.weights_dialog:

` <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">

<com.github.badoualy.datepicker.DatePickerTimeline
    android:id="@+id/datePickerTimeLine"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="15dp"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/tvWeights"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker
        android:id="@+id/npWeight"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        app:snp_scrollEnabled="true"
        app:snp_updateInterval="5" />

</LinearLayout>

`

Thanks in advance for any assistance.