Example usage for android.widget TextView getCurrentHintTextColor

List of usage examples for android.widget TextView getCurrentHintTextColor

Introduction

In this page you can find the example usage for android.widget TextView getCurrentHintTextColor.

Prototype

@ColorInt
public final int getCurrentHintTextColor() 

Source Link

Document

Return the current color selected to paint the hint text.

Usage

From source file:com.finchuk.clock2.alarms.ui.BaseAlarmViewHolder.java

private void bindTime(Alarm alarm) {
    String time = DateFormat.getTimeFormat(getContext()).format(new Date(alarm.ringsAt()));
    if (DateFormat.is24HourFormat(getContext())) {
        mTime.setText(time);/*from w w w .  j a v  a  2 s .com*/
    } else {
        TimeTextUtils.setText(time, mTime);
    }

    // Use a mock TextView to get our colors, because its ColorStateList is never
    // mutated for the lifetime of this ViewHolder (even when reused).
    // This solution is robust against dark/light theme changes, whereas using
    // color resources is not.
    TextView colorsSource = (TextView) itemView.findViewById(R.id.colors_source);
    ColorStateList colors = colorsSource.getTextColors();
    int def = colors.getDefaultColor();
    // Too light
    //        int disabled = colors.getColorForState(new int[] {-android.R.attr.state_enabled}, def);
    // Material guidelines say text hints and disabled text should have the same color.
    int disabled = colorsSource.getCurrentHintTextColor();
    // However, digging around in the system's textColorHint for 21+ says its 50% black for our
    // light theme. I'd like to follow what the guidelines says, but I want code that is robust
    // against theme changes. Alternatively, override the attribute values to what you want
    // in both your dark and light themes...
    //        int disabled = ContextCompat.getColor(getContext(), R.color.text_color_disabled_light);
    // We only have two states, so we don't care about losing the other state colors.
    mTime.setTextColor(alarm.isEnabled() ? def : disabled);
}