Example usage for android.widget ImageView setImageTintList

List of usage examples for android.widget ImageView setImageTintList

Introduction

In this page you can find the example usage for android.widget ImageView setImageTintList.

Prototype

public void setImageTintList(@Nullable ColorStateList tint) 

Source Link

Document

Applies a tint to the image drawable.

Usage

From source file:Main.java

public static void setImageTintList(ImageView imageView, ColorStateList colorStateList) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        imageView.setImageTintList(colorStateList);
    }/*from w  w  w.j a  v a2s. c o m*/
}

From source file:com.xebia.xsdnl.innorater.Crap.java

public static void showNearbyStateInImageView(ImageView iv, boolean enabled) {
    if (enabled) {
        iv.setImageResource(R.drawable.logo_nearby_color_48dp);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            iv.setImageTintList(null);
        }/*  w w w. j a v  a 2  s. c  o m*/
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            iv.setImageResource(R.drawable.ic_nearby_white_48dp);
            iv.setImageTintList(iv.getResources().getColorStateList(R.color.primary_text_disabled_light));
        } else {
            Drawable raw = iv.getResources().getDrawable(R.drawable.ic_nearby_white_48dp);
            Drawable tintable = DrawableCompat.wrap(raw);
            DrawableCompat.setTint(tintable, iv.getResources().getColor(R.color.primary_text_disabled_light));
            iv.setImageDrawable(tintable);
        }
    }
}

From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java

public static void setImageTintList(ImageView imageView, ColorStateList colorStateList) {
    if (isApi_21_OrHigher()) {
        imageView.setImageTintList(colorStateList);
    } else {/*from   www .j a va 2  s. co m*/
        Drawable drawable = imageView.getDrawable();

        if (drawable != null) {
            Drawable wrapped = DrawableCompat.wrap(drawable);
            DrawableCompat.setTintList(wrapped, colorStateList);
            imageView.setImageDrawable(wrapped);
        }
    }
}

From source file:uk.ac.horizon.artcodes.scanner.ScannerActivity.java

private void createSettingsUI(List<DetectorSetting> settings) {
    settingIcons.removeAllViews();//  ww w .  j ava 2  s. c  om
    if (settings != null && !settings.isEmpty()) {
        final int padding = getResources().getDimensionPixelSize(R.dimen.setting_padding);
        List<DetectorSetting> settingList = settings;
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            settingList = Lists.reverse(settings);
        }
        for (final DetectorSetting setting : settingList) {
            final ImageView button = new ImageView(this);
            button.setContentDescription(getString(setting.getText()));
            final int[] attrs = new int[] { android.R.attr.selectableItemBackground };
            final TypedArray ta = obtainStyledAttributes(attrs);
            final Drawable drawableFromTheme = ta.getDrawable(0);
            ta.recycle();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                button.setImageResource(setting.getIcon());
                button.setImageTintList(ColorStateList.valueOf(Color.WHITE));
                button.setBackground(drawableFromTheme);
            } else {
                button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE));
                //noinspection deprecation
                button.setBackgroundDrawable(drawableFromTheme);
            }

            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    setting.nextValue();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        button.setImageResource(setting.getIcon());
                    } else {
                        button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE));
                    }
                    button.setContentDescription(getString(setting.getText()));
                    textAnimator.setText(setting.getText());
                }
            });
            final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1);
            params.weight = 1;
            button.setLayoutParams(params);
            settingIcons.addView(button);
            button.setPadding(padding, padding, padding, padding);
        }

    }

    menuAnimator.setViewVisible(settingIcons.getChildCount() > 0);
}

From source file:com.almeida.matheus.androidslidingtabmaterialdesigner.Components.SlidingTabLayout.java

private void populateTabStrip() {

    final TabsAdapter adapter = (TabsAdapter) mViewPager.getAdapter();

    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from   ww  w. j av a 2s .co  m*/
        ImageView textTab = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            textTab = (ImageView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (textTab == null && ImageView.class.isInstance(tabView)) {
            textTab = (ImageView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);

        textTab.setImageResource(adapter.getPageIconResId(i));
        textTab.setImageTintList(getResources().getColorStateList(R.color.item_selector));

        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.android.contacts.list.ContactListItemView.java

private void addStarImageHeader() {
    mHeaderView = new ImageView(getContext());
    final ImageView headerImageView = (ImageView) mHeaderView;
    headerImageView.setImageDrawable(/*  ww w. j a v a2  s.  com*/
            getResources().getDrawable(R.drawable.quantum_ic_star_vd_theme_24, getContext().getTheme()));
    headerImageView
            .setImageTintList(ColorStateList.valueOf(getResources().getColor(R.color.material_star_pink)));
    headerImageView.setContentDescription(getContext().getString(R.string.contactsFavoritesLabel));
    headerImageView.setVisibility(View.VISIBLE);
    addView(headerImageView);
}

From source file:com.mobileglobe.android.customdialer.common.list.ContactListItemView.java

/**
 * Set drawable resources directly for the drawable resource of the photo view.
 *
 * @param drawableId Id of drawable resource.
 *///from   w w  w .  j a va2  s  . c o m
public void setDrawableResource(int drawableId) {
    ImageView photo = getPhotoView();
    photo.setScaleType(ScaleType.CENTER);
    final Drawable drawable = ContextCompat.getDrawable(getContext(), drawableId);
    final int iconColor = ContextCompat.getColor(getContext(), R.color.search_shortcut_icon_color);
    if (CompatUtils.isLollipopCompatible()) {
        photo.setImageDrawable(drawable);
        photo.setImageTintList(ColorStateList.valueOf(iconColor));
    } else {
        final Drawable drawableWrapper = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTint(drawableWrapper, iconColor);
        photo.setImageDrawable(drawableWrapper);
    }
}

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Set drawable resources directly for the drawable resource of the photo view.
 *
 * @param drawableId Id of drawable resource.
 *//*  ww w . j  a  va  2 s.co m*/
public void setDrawableResource(int drawableId) {
    ImageView photo = getPhotoView();
    photo.setScaleType(ImageView.ScaleType.CENTER);
    final Drawable drawable = ContextCompat.getDrawable(getContext(), drawableId);
    final int iconColor = ContextCompat.getColor(getContext(), R.color.search_shortcut_icon_color);
    if (CompatUtils.isLollipopCompatible()) {
        photo.setImageDrawable(drawable);
        photo.setImageTintList(ColorStateList.valueOf(iconColor));
    } else {
        final Drawable drawableWrapper = DrawableCompat.wrap(drawable).mutate();
        DrawableCompat.setTint(drawableWrapper, iconColor);
        photo.setImageDrawable(drawableWrapper);
    }
}

From source file:com.android.dialer.DialtactsFragment.java

/**
 * @author bbk wangchunhe/*from  w w  w .  java  2  s.  co m*/
 * @Date 2016/07/15
 * add PopupWindow OnClickListener
 * @param popupWindow
 */
private void popupWindowItemSelect(final PopupWindow popupWindow) {
    View contentView = popupWindow.getContentView();
    RelativeLayout callLogsContainer = (RelativeLayout) contentView
            .findViewById(R.id.dialtacts_popupwindow_all_calls_cantainer);
    final TextView callLogsTxt = (TextView) contentView.findViewById(R.id.dialtacts_popupwindow_all_calls_txt);
    final ImageView callLogsImage = (ImageView) contentView
            .findViewById(R.id.dialtacts_popupwindow_all_calls_image);

    RelativeLayout callLogMissedContainer = (RelativeLayout) contentView
            .findViewById(R.id.dialtacts_popupwindow_call_log_missed_container);
    final TextView callLogMissedTxt = (TextView) contentView
            .findViewById(R.id.dialtacts_popupwindow_call_log_missed_txt);
    final ImageView callLogMissedImage = (ImageView) contentView
            .findViewById(R.id.dialtacts_popupwindow_call_log_missed_image);

    ColorStateList colorStateListTxt = getActivity().getColorStateList(R.color.popupwindows_item_text_color);
    ColorStateList colorStateListImage = getActivity().getColorStateList(R.color.popupwindows_item_image_color);

    callLogsImage.setImageTintList(colorStateListImage);
    callLogMissedImage.setImageTintList(colorStateListImage);

    callLogsTxt.setTextColor(colorStateListTxt);
    callLogMissedTxt.setTextColor(colorStateListTxt);

    if (!callLogMissedImage.isSelected()) {
        callLogsImage.setSelected(true);
        callLogsTxt.setSelected(true);
    }

    callLogsContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            callLogsImage.setSelected(true);
            callLogsTxt.setSelected(true);
            callLogMissedImage.setSelected(false);
            callLogMissedTxt.setSelected(false);
            showCallLogFragment(CallLogQueryHandler.CALL_TYPE_ALL);
            //                mActionbarNameTxt.setText(getString(R.string.all_calls));
            //                mDialtactsActionBarController.setActionNameAndMenu(R.string.all_calls,R.string.call_log_missed,R.string.select_call_log);
            Log.e(TAG, " action Name  --1" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mDialtactsActionBarController.setActionName(getString(R.string.all_calls));
            Log.e(TAG, " action Name  --2" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mCallLogSelectPopupWindow.dismiss();

        }
    });

    callLogMissedContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            callLogsImage.setSelected(false);
            callLogsTxt.setSelected(false);
            callLogMissedImage.setSelected(true);
            callLogMissedTxt.setSelected(true);
            showCallLogFragment(Calls.MISSED_TYPE);
            //                mActionbarNameTxt.setText(getString(R.string.call_log_missed));
            //                mDialtactsActionBarController.setActionNameAndMenu(R.string.all_calls,R.string.call_log_missed,R.string.select_call_log);
            Log.e(TAG, " action Name  --3" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mDialtactsActionBarController.setActionName(getString(R.string.call_log_missed));
            Log.e(TAG, " action Name  --4" + mDialtactsActionBarController.getmActionNameTxt().getText());
            mCallLogSelectPopupWindow.dismiss();

        }
    });

}