android.support.v4.view.ViewCompat#setBackgroundTintList ( )源码实例Demo

下面列出了android.support.v4.view.ViewCompat#setBackgroundTintList ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: IncDec   文件: IncDecCircular.java
/** 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));
    }
}
 
源代码2 项目: IncDec   文件: IncDecCircular.java
/** 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));
    }

}
 
源代码3 项目: IncDec   文件: IncDecImageButton.java
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);
}
 
源代码4 项目: IncDec   文件: IncDecImageButton.java
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);

}
 
源代码5 项目: AwesomeValidation   文件: UnderlabelValidator.java
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));
        }
    };
}
 
源代码6 项目: andela-crypto-app   文件: Easel.java
/**
 * 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);
}
 
源代码7 项目: AndroidTint   文件: EmBackgroundTintHelper.java
/**
 *
 * @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();
    }
}
 
源代码8 项目: Saude-no-Mapa   文件: LoginActivity.java
@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));
    }
}
 
源代码9 项目: IndexableRecyclerView   文件: IndexableLayout.java
/**
 * display Material Design OverlayView
 */
public void setOverlayStyle_MaterialDesign(int color) {
    if (mMDOverlay == null) {
        initMDOverlay(color);
    } else {
        ViewCompat.setBackgroundTintList(mMDOverlay, ColorStateList.valueOf(color));
    }
    mCenterOverlay = null;
}
 
@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;
}
 
源代码11 项目: AwesomeValidation   文件: ViewsInfo.java
public void restoreViews() {
    if (!mIsOriginal) {
        ViewCompat.setBackgroundTintList(mEditText, mColorStateList);
        mEditText.requestFocus();
        mNewContainer.removeView(mEditText);
        mParent.removeView(mNewContainer);
        mParent.addView(mEditText, mIndex);
        mIsOriginal = true;
    }
}
 
源代码12 项目: AwesomeValidation   文件: ViewsInfoTest.java
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);
}
 
源代码13 项目: aircon   文件: CompatBackgroundTintColorSetter.java
@Override
protected void setAttr(final View view, final int color) {
	ViewCompat.setBackgroundTintList(view, ColorStateList.valueOf(color));
}
 
源代码14 项目: youqu_master   文件: MaterialIntroActivity.java
private void tintButtons(ColorStateList color) {
    ViewCompat.setBackgroundTintList(nextButton, color);
    ViewCompat.setBackgroundTintList(backButton, color);
    ViewCompat.setBackgroundTintList(skipButton, color);
}
 
private void tintButtons(ColorStateList color) {
    ViewCompat.setBackgroundTintList(nextButton, color);
    ViewCompat.setBackgroundTintList(backButton, color);
    ViewCompat.setBackgroundTintList(skipButton, color);
}
 
源代码16 项目: Puff-Android   文件: SimpleSlide.java
@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;
}
 
源代码17 项目: android-mvvm-with-tests   文件: UiUtils.java
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));
}
 
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;
    }
 
 同类方法