Java Code Examples for android.support.v4.view.ViewCompat#setBackgroundTintList()

The following examples show how to use android.support.v4.view.ViewCompat#setBackgroundTintList() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IncDecCircular.java    From IncDec with Apache License 2.0 6 votes vote down vote up
/** Setting up the right button */
private void setupRightButton(FloatingActionButton rightButton, Drawable rightSrc,
                              int rightButtonTint, int rightDrawableTint) {
    if(rightSrc!=null) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            rightSrc.setTintList(new ColorStateList(new int[][]{new int[]{0}},
                    new int[]{rightDrawableTint}));
        }
        else
        {
            final Drawable wrappedDrawable = DrawableCompat.wrap(rightSrc);
            DrawableCompat.setTintList(wrappedDrawable, ColorStateList.valueOf(rightDrawableTint));
        }
        rightButton.setImageDrawable(rightSrc);
    }
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        rightButton.setBackgroundTintList(new ColorStateList(new int[][]{new int[]{0}},
                new int[]{rightButtonTint}));
    }
    else
    {
        ViewCompat.setBackgroundTintList(rightButton, ColorStateList.valueOf(rightButtonTint));
    }
}
 
Example 2
Source File: IncDecCircular.java    From IncDec with Apache License 2.0 6 votes vote down vote up
/** Setting up the left button */
private void setupLeftButton(FloatingActionButton leftButton, Drawable leftSrc,
                             int leftButtonTint, int leftDrawableTint) {
    if(leftSrc!=null) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            leftSrc.setTintList(new ColorStateList(new int[][]{new int[]{0}},
                    new int[]{leftDrawableTint}));
        }
        else
        {
            final Drawable wrappedDrawable = DrawableCompat.wrap(leftSrc);
            DrawableCompat.setTintList(wrappedDrawable, ColorStateList.valueOf(leftDrawableTint));
        }
        leftButton.setImageDrawable(leftSrc);

    }
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        leftButton.setBackgroundTintList(new ColorStateList(new int[][]{new int[]{0}},
                new int[]{leftButtonTint}));
    }
    else
    {
        ViewCompat.setBackgroundTintList(leftButton, ColorStateList.valueOf(leftButtonTint));
    }

}
 
Example 3
Source File: IncDecImageButton.java    From IncDec with Apache License 2.0 6 votes vote down vote up
private void setupRightButton(ImageButton rightButton, Drawable rightSrc,
                              int rightButtonTint, int rightDrawableTint, Drawable background) {
    if(rightSrc!=null) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            rightSrc.setTintList(new ColorStateList(new int[][]{new int[]{0}},
                    new int[]{rightDrawableTint}));
        }
        else
        {
            final Drawable wrappedDrawable = DrawableCompat.wrap(rightSrc);
            DrawableCompat.setTintList(wrappedDrawable, ColorStateList.valueOf(rightDrawableTint));
        }
        rightButton.setImageDrawable(rightSrc);
    }
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        rightButton.setBackgroundTintList(new ColorStateList(new int[][]{new int[]{0}},
                new int[]{rightButtonTint}));
    }
    else
    {
        ViewCompat.setBackgroundTintList(rightButton, ColorStateList.valueOf(rightButtonTint));
    }
    rightButton.setBackground(background);
}
 
Example 4
Source File: IncDecImageButton.java    From IncDec with Apache License 2.0 6 votes vote down vote up
private void setupLeftButton(ImageButton leftButton, Drawable leftSrc,
                             int leftButtonTint, int leftDrawableTint,Drawable background) {
    if(leftSrc!=null) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            leftSrc.setTintList(new ColorStateList(new int[][]{new int[]{0}},
                    new int[]{leftDrawableTint}));
        }
        else
        {
            final Drawable wrappedDrawable = DrawableCompat.wrap(leftSrc);
            DrawableCompat.setTintList(wrappedDrawable, ColorStateList.valueOf(leftDrawableTint));
        }
        leftButton.setImageDrawable(leftSrc);
    }
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        leftButton.setBackgroundTintList(new ColorStateList(new int[][]{new int[]{0}},
                new int[]{leftButtonTint}));
    }
    else
    {
        ViewCompat.setBackgroundTintList(leftButton, ColorStateList.valueOf(leftButtonTint));
    }
    leftButton.setBackground(background);

}
 
Example 5
Source File: UnderlabelValidator.java    From AwesomeValidation with MIT License 6 votes vote down vote up
private void init() {
    mValidationCallback = new ValidationCallback() {
        @Override
        public void execute(ValidationHolder validationHolder, Matcher matcher) {
            TextView textView = replaceView(validationHolder);
            if (AwesomeValidation.isAutoFocusOnFirstFailureEnabled() && !mHasFailed) {
                textView.setFocusable(true);
                textView.setFocusableInTouchMode(true);
                textView.setClickable(true);
                textView.requestFocus();
                mHasFailed = true;
            }
            ViewCompat.setBackgroundTintList(validationHolder.getEditText(), ColorStateList.valueOf(mColor));
        }
    };
}
 
Example 6
Source File: ViewsInfoTest.java    From AwesomeValidation with MIT License 5 votes vote down vote up
public void testRestoreViews() {
    mViewsInfo.restoreViews();
    ViewCompat.setBackgroundTintList(mMockEditText, mMockColorStateList);
    InOrder order = inOrder(mMockEditText, mMockNewContainer, mMockParent);
    order.verify(mMockEditText).requestFocus();
    order.verify(mMockNewContainer).removeView(mMockEditText);
    order.verify(mMockParent).removeView(mMockNewContainer);
    order.verify(mMockParent).addView(mMockEditText, mIndex);
}
 
Example 7
Source File: Easel.java    From andela-crypto-app with Apache License 2.0 5 votes vote down vote up
/**
 * Tint the button
 *
 * @param button the button
 * @param color  the color
 */
public static void tint(@NonNull Button button, @ColorInt int color) {
    ColorStateList sl = new ColorStateList(new int[][]{
            new int[]{}
    }, new int[]{
            color
    });
    ViewCompat.setBackgroundTintList(button, sl);
}
 
Example 8
Source File: EmBackgroundTintHelper.java    From AndroidTint with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param view
 * @param attrs
 * @param defStyleAttr
 */
public static void loadFromAttributes(View view, AttributeSet attrs, int defStyleAttr) {
    TypedArray a = view.getContext().obtainStyledAttributes(attrs, R.styleable.EmBackgroundTintHelper, defStyleAttr, 0);
    try {
        if (a.hasValue(R.styleable.EmBackgroundTintHelper_backgroundTint)) {
            ViewCompat.setBackgroundTintList(view, a.getColorStateList(R.styleable.EmBackgroundTintHelper_backgroundTint));
        }
        if (a.hasValue(R.styleable.EmBackgroundTintHelper_backgroundTintMode)) {
            ViewCompat.setBackgroundTintMode(view, DrawableUtils.parseTintMode( a.getInt(R.styleable.EmBackgroundTintHelper_backgroundTintMode, -1), null));
        }
    } finally {
        a.recycle();
    }
}
 
Example 9
Source File: LoginActivity.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);

    mPresenter = new LoginPresenterImpl(this, this);

    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP && loginFacebookButton instanceof AppCompatButton) {
        ((AppCompatButton) loginFacebookButton).setSupportBackgroundTintList(getResources().getColorStateList(R.color.facebook_blue));
    } else {
        ViewCompat.setBackgroundTintList(loginFacebookButton, getResources().getColorStateList(R.color.facebook_blue));
    }
}
 
Example 10
Source File: ViewsInfo.java    From AwesomeValidation with MIT License 5 votes vote down vote up
public void restoreViews() {
    if (!mIsOriginal) {
        ViewCompat.setBackgroundTintList(mEditText, mColorStateList);
        mEditText.requestFocus();
        mNewContainer.removeView(mEditText);
        mParent.removeView(mNewContainer);
        mParent.addView(mEditText, mIndex);
        mIsOriginal = true;
    }
}
 
Example 11
Source File: IndexableLayout.java    From IndexableRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * display Material Design OverlayView
 */
public void setOverlayStyle_MaterialDesign(int color) {
    if (mMDOverlay == null) {
        initMDOverlay(color);
    } else {
        ViewCompat.setBackgroundTintList(mMDOverlay, ColorStateList.valueOf(color));
    }
    mCenterOverlay = null;
}
 
Example 12
Source File: MaterialContentOverflow.java    From MaterialContentOverflow with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    overflowGestureListener.clearReferences();
    ViewCompat.setBackgroundTintList(fab, null);
    fab.setImageResource(0);
    fab.setImageDrawable(null);
    fab.setImageBitmap(null);
    fab = null;
    contentFrame = null;
}
 
Example 13
Source File: MaterialIntroActivity.java    From material-intro-screen with MIT License 4 votes vote down vote up
private void tintButtons(ColorStateList color) {
    ViewCompat.setBackgroundTintList(nextButton, color);
    ViewCompat.setBackgroundTintList(backButton, color);
    ViewCompat.setBackgroundTintList(skipButton, color);
}
 
Example 14
Source File: UiUtils.java    From android-mvvm-with-tests with MIT License 4 votes vote down vote up
public static void resetTintColor(Context context, View view) {
    TintManager tintManager = TintManager.get(context);
    ViewCompat.setBackgroundTintList(view,
            tintManager.getTintList(android.support.design.R.drawable.abc_edit_text_material));
}
 
Example 15
Source File: SimpleSlide.java    From Puff-Android with MIT License 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    Bundle arguments = getArguments();

    View fragment = inflater.inflate(arguments.getInt(ARGUMENT_LAYOUT_RES,
            R.layout.fragment_simple_slide), container, false);

    TextView titleView = (TextView) fragment.findViewById(R.id.mi_title);
    TextView descriptionView = (TextView) fragment.findViewById(R.id.mi_description);
    buttonGrantPermissions = (Button) fragment.findViewById(R.id.mi_button_grant_permissions);
    ImageView imageView = (ImageView) fragment.findViewById(R.id.mi_image);

    CharSequence title = arguments.getCharSequence(ARGUMENT_TITLE);
    int titleRes = arguments.getInt(ARGUMENT_TITLE_RES);
    CharSequence description = arguments.getCharSequence(ARGUMENT_DESCRIPTION);
    int descriptionRes = arguments.getInt(ARGUMENT_DESCRIPTION_RES);
    int imageRes = arguments.getInt(ARGUMENT_IMAGE_RES);
    int backgroundRes = arguments.getInt(ARGUMENT_BACKGROUND_RES);
    int backgroundDarkRes = arguments.getInt(ARGUMENT_BACKGROUND_DARK_RES);

    //Title
    if (titleView != null) {
        if (title != null) {
            titleView.setText(title);
            titleView.setVisibility(View.VISIBLE);
        } else if (titleRes != 0) {
            titleView.setText(titleRes);
            titleView.setVisibility(View.VISIBLE);
        } else {
            titleView.setVisibility(View.GONE);
        }
    }

    //Description
    if (descriptionView != null) {
        if (description != null) {
            descriptionView.setText(description);
            descriptionView.setVisibility(View.VISIBLE);
        } else if (descriptionRes != 0) {
            descriptionView.setText(descriptionRes);
            descriptionView.setVisibility(View.VISIBLE);
        } else {
            descriptionView.setVisibility(View.GONE);
        }
    }

    //Image
    if (imageView != null) {
        if (imageRes != 0) {
            imageView.setImageResource(imageRes);
            imageView.setVisibility(View.VISIBLE);
        } else {
            imageView.setVisibility(View.GONE);
        }
    }

    if (backgroundDarkRes != 0 && buttonGrantPermissions != null) {
        ViewCompat.setBackgroundTintList(buttonGrantPermissions, ColorStateList.valueOf(
                ContextCompat.getColor(getContext(), backgroundDarkRes)));
    }
    
    @ColorInt
    int textColorPrimary;
    @ColorInt
    int textColorSecondary;

    if (backgroundRes != 0 &&
            ColorUtils.calculateLuminance(ContextCompat.getColor(getContext(), backgroundRes)) < 0.6) {
        //Use light text color
        textColorPrimary = ContextCompat.getColor(getContext(), R.color.mi_text_color_primary_dark);
        textColorSecondary = ContextCompat.getColor(getContext(), R.color.mi_text_color_secondary_dark);
    } else {
        //Use dark text color
        textColorPrimary = ContextCompat.getColor(getContext(), R.color.mi_text_color_primary_light);
        textColorSecondary = ContextCompat.getColor(getContext(), R.color.mi_text_color_secondary_light);
    }
    
    if (titleView != null) {
        titleView.setTextColor(textColorPrimary);
    }
    if (descriptionView != null) {
        descriptionView.setTextColor(textColorSecondary);
    }
    if (buttonGrantPermissions != null) {
        buttonGrantPermissions.setTextColor(textColorPrimary);
    }

    return fragment;
}
 
Example 16
Source File: CompatBackgroundTintColorSetter.java    From aircon with MIT License 4 votes vote down vote up
@Override
protected void setAttr(final View view, final int color) {
	ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(color));
}
 
Example 17
Source File: MaterialIntroActivity.java    From youqu_master with Apache License 2.0 4 votes vote down vote up
private void tintButtons(ColorStateList color) {
    ViewCompat.setBackgroundTintList(nextButton, color);
    ViewCompat.setBackgroundTintList(backButton, color);
    ViewCompat.setBackgroundTintList(skipButton, color);
}
 
Example 18
Source File: MaterialContentOverflow.java    From MaterialContentOverflow with Apache License 2.0 2 votes vote down vote up
private FloatingActionButton createFab(Context context, int buttonDrawable, int buttonColor, int buttonPosition) {

        fab = new TintFloatingActionButton(context);

        int fabElevationInPixels = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());

        LayoutParams fabLayoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        fabMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());

        if (buttonPosition == RIGHT) {

            fabLayoutParams.gravity = Gravity.END | Gravity.TOP;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                fabLayoutParams.setMarginEnd(fabMargin);
            } else {
                fabLayoutParams.rightMargin = fabMargin;
            }

        } else if (buttonPosition == CENTER) {
            fabLayoutParams.gravity = Gravity.CENTER | Gravity.TOP;
        } else {

            fabLayoutParams.gravity = Gravity.START | Gravity.TOP;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                fabLayoutParams.setMarginStart(fabMargin);
            } else {
                fabLayoutParams.leftMargin = fabMargin;
            }

        }

        fabLayoutParams.bottomMargin = fabMargin;
        fabLayoutParams.topMargin = fabMargin;

        if (buttonDrawable > 0) {
            fab.setImageDrawable(ContextCompat.getDrawable(context, buttonDrawable));
        }

        if (buttonColor > 0) {
            ViewCompat.setBackgroundTintList(fab, ContextCompat.getColorStateList(context, buttonColor));
        }

        ViewCompat.setElevation(fab, fabElevationInPixels);

        fab.setLayoutParams(fabLayoutParams);

        fab.setTag("FAB");

        this.addView(fab);

        return fab;
    }