Java Code Examples for android.widget.TextView.getCompoundDrawablesRelative()

The following are Jave code examples for showing how to use getCompoundDrawablesRelative() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: ulogger-android   File: MainActivity.java   Source Code and License Vote up 6 votes
/**
 * Set status led color
 * @param led Led text view
 * @param color Color (red, yellow or green)
 */
private void setLedColor(TextView led, int color) {
    Drawable l;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        l = led.getCompoundDrawables()[0];
    } else {
        l = led.getCompoundDrawablesRelative()[0];
    }
    switch (color) {
        case LED_RED:
            l.setColorFilter(ContextCompat.getColor(this, R.color.colorRed), PorterDuff.Mode.SRC_ATOP);
            break;

        case LED_GREEN:
            l.setColorFilter(ContextCompat.getColor(this, R.color.colorGreen), PorterDuff.Mode.SRC_ATOP);
            break;

        case LED_YELLOW:
            l.setColorFilter(ContextCompat.getColor(this, R.color.colorYellow), PorterDuff.Mode.SRC_ATOP);
            break;
    }
    l.invalidateSelf();
}