Example usage for android.widget ImageView setBackgroundColor

List of usage examples for android.widget ImageView setBackgroundColor

Introduction

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

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:com.musenkishi.atelier.Atelier.java

private static void applyColorToView(final ImageView imageView, int color, boolean fromCache,
        boolean shouldMask) {
    if (fromCache) {
        if (shouldMask) {
            if (imageView.getDrawable() != null) {
                imageView.getDrawable().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            } else if (imageView.getBackground() != null) {
                imageView.getBackground().mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
            }/*from   w w w.  java  2 s  .  c  o m*/
        } else {
            imageView.setBackgroundColor(color);
        }
    } else {
        if (shouldMask) {
            Integer colorFrom;
            ValueAnimator.AnimatorUpdateListener imageAnimatorUpdateListener = new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    if (imageView.getDrawable() != null) {
                        imageView.getDrawable().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    } else if (imageView.getBackground() != null) {
                        imageView.getBackground().mutate().setColorFilter(
                                (Integer) valueAnimator.getAnimatedValue(), PorterDuff.Mode.MULTIPLY);
                    }
                }
            };
            ValueAnimator.AnimatorUpdateListener animatorUpdateListener;

            PaletteTag paletteTag = (PaletteTag) imageView.getTag(viewTagKey);
            animatorUpdateListener = imageAnimatorUpdateListener;
            colorFrom = paletteTag.getColor();
            imageView.setTag(viewTagKey, new PaletteTag(paletteTag.getId(), color));

            Integer colorTo = color;
            ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
            colorAnimation.addUpdateListener(animatorUpdateListener);
            colorAnimation.setDuration(300);
            colorAnimation.start();
        } else {
            Drawable preDrawable;

            if (imageView.getBackground() == null) {
                preDrawable = new ColorDrawable(Color.TRANSPARENT);
            } else {
                preDrawable = imageView.getBackground();
            }

            TransitionDrawable transitionDrawable = new TransitionDrawable(
                    new Drawable[] { preDrawable, new ColorDrawable(color) });
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                imageView.setBackground(transitionDrawable);
            } else {
                imageView.setBackgroundDrawable(transitionDrawable);
            }
            transitionDrawable.startTransition(300);
        }
    }
}

From source file:com.flan.stock.fragment.FragmentNewsYw.java

/**
 * ???/*w w  w . j a  va  2  s  . c  o  m*/
 */
private void getTouTiaoData() {

    LayoutParams para = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    ImageView img1 = new ImageView(context);
    img1.setBackgroundResource(R.drawable.img_ipo);
    img1.setLayoutParams(para);
    ImageView img2 = new ImageView(context);
    img2.setBackgroundColor(Color.BLUE);
    img2.setLayoutParams(para);
    toutiaoList = new ArrayList<>();
    toutiaoList.add(img1);
    toutiaoList.add(img2);
}

From source file:edu.ucsb.cs.cs190i.papertown.town.newtown.SelectImageGridAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View grid;/*ww  w .ja  va2 s.c o  m*/
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {
        if (position != imageUris.size()) {
            grid = inflater.inflate(R.layout.grid_single_newtown_selectimage, null);
            imageView = (ImageView) grid.findViewById(R.id.grid_image);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (mContext.checkSelfPermission(
                        Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

                    // Should we show an explanation?
                    if (ActivityCompat.shouldShowRequestPermissionRationale((SelectImageActivity) mContext,
                            Manifest.permission.READ_EXTERNAL_STORAGE)) {
                        // Explain to the user why we need to read the contacts
                        Log.i("my", "permission.READ_EXTERNAL_STORAGE");

                    }

                    ActivityCompat.requestPermissions((SelectImageActivity) mContext,
                            new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                            MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

                    // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
                    // app-defined int constant

                    //                        return;
                } else {
                    Log.i("my", "permission.READ_EXTERNAL_STORAGE3");
                    //normal request goes here
                    //imageView.setImageURI(ImageUris[position]);
                    Picasso.with(mContext).load(imageUris.get(position)).fit().into(imageView);
                }
            }

        } else {
            grid = inflater.inflate(R.layout.grid_single_newtown_selectimage, null);
            ImageView imageView = (ImageView) grid.findViewById(R.id.grid_image);
            imageView.setBackgroundColor(Color.GRAY);
            imageView.setImageResource(R.drawable.ic_add_white_24dp);
        }
    } else {
        grid = (View) convertView;
    }

    return grid;
}

From source file:com.ccwant.photo.selector.activity.CCwantPhotoBrowserActivity.java

private void initListViews(String path) {

    ImageView img = new ImageView(this);// textView
    img.setBackgroundColor(0xff000000);
    img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    listViews.add(img);// view
}

From source file:com.example.nikhil.wikipediasearch.ImageAdapter.java

private void zoomImageFromThumb(final View thumbView, int imageId) {
    // If there's an animation in progress, cancel it immediately and
    // proceed with this one.
    int startIndex = 0;
    int lastIndex = 0;

    // Load the high-resolution "zoomed-in" image.
    final ImageView expandedImageView = (ImageView) ((Activity) thumbView.getContext())
            .findViewById(R.id.expanded_image);

    expandedImageView.setBackgroundColor(ContextCompat.getColor(thumbView.getContext(), R.color.Color_1));
    String newURL = URLS[imageId].replace("/thumb", "");

    lastIndex = newURL.lastIndexOf("/");

    String newURLSubString = newURL.substring(lastIndex);

    newURL = newURL.replace(newURLSubString, "");

    int width = thumbView.getContext().getResources().getDisplayMetrics().widthPixels;
    int height = thumbView.getContext().getResources().getDisplayMetrics().heightPixels;

    Picasso.with(thumbView.getContext()).load(newURL).noFade().resize(width, height / 2).centerCrop()
            .error(R.drawable.no_image).placeholder(R.drawable.progress_animation)
            .into((ImageView) expandedImageView);

    Log.d(TAG, "setOnClickListener" + newURL);

    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the
    // top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);/* ww w  .j  av  a2s  .c om*/
    expandedImageView.setPivotY(0f);

    // Upon clicking the zoomed-in image, it should zoom back down to the
    // original bounds
    // and show the thumbnail instead of the expanded image.
    //final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            expandedImageView.setVisibility(View.GONE);
        }
    });
}

From source file:com.wlzndjk.poker.widget.MyHScrollView.java

private void updateTabStyles() {

    for (int i = 0; i < tabCount; i++) {

        View v = tabsContainer.getChildAt(i);

        if (v instanceof ImageView) {
            ImageView tab = (ImageView) v;
            if (i == selectedPosition) {
                tab.setBackgroundColor(Color.parseColor(tabBackgroundColor));
                if (selectedPosition == 0) {
                    mLeft.setImageResource(R.drawable.left_normal);
                    mRight.setImageResource(R.drawable.right_pressed);
                } else if (selectedPosition == tabCount - 1) {
                    mLeft.setImageResource(R.drawable.left_pressed);
                    mRight.setImageResource(R.drawable.right_normal);
                } else {
                    mLeft.setImageResource(R.drawable.left_pressed);
                    mRight.setImageResource(R.drawable.right_pressed);
                }// w  ww  . ja va2s .com
            } else {
                tab.setBackgroundColor(Color.parseColor(tabselectedBackgroundColor));

            }
        }
    }

}

From source file:com.example.android.tourguide.CategoryAdaptor.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    View listItemView = convertView;
    if (listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }//from  ww w.  j a va 2 s.co m

    // Get the {@link Category} object located at this position in the list
    Category currentCategory = getItem(position);

    // Find the TextView in the list_item.xml layout with the ID category_view.
    TextView categoryView = (TextView) listItemView.findViewById(R.id.catergory_view);
    // Get the Category from the currentCategry object and set this text on
    // the Category TextView.
    categoryView.setText(currentCategory.getCategory());

    // Set the theme color for the list item
    View textContainer = listItemView.findViewById(R.id.text_container);
    // Find the color that resource ID maps
    int color = ContextCompat.getColor(getContext(), mColorResourceID);
    // Set the background color of the text container view
    textContainer.setBackgroundColor(color);

    // Find the ImageView in the list_item.xml layout with the ID image.
    ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);

    if (currentCategory.hasImage()) {
        // Set the image view to the image resource specified in the current word.
        imageView.setImageResource(currentCategory.getImageResourceId());
        // Find the color that resource ID maps
        imageView.setBackgroundColor(color);

        // Make sure the view is Visible
        imageView.setVisibility(View.VISIBLE);
    } else {
        imageView.setVisibility(View.GONE);
    }

    // Return the whole list item layout so that it can be shown in
    // the ListView.
    return listItemView;
}

From source file:ch.bfh.instacircle.ParticipantCursorAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {

    // extracting the labels of the layout
    TextView content = (TextView) view.findViewById(R.id.content);
    TextView description = (TextView) view.findViewById(R.id.description);
    ImageView icon = (ImageView) view.findViewById(R.id.icon);

    // setting the content label
    content.setText(cursor.getString(cursor.getColumnIndex("identification")));

    // setting the icon according to the participant's state
    switch (cursor.getInt(cursor.getColumnIndex("state"))) {
    case 0://  w  w  w  .  j  a  v a  2s.  co m
        description.setText("inactive participant");
        icon.setBackgroundColor(context.getResources().getColor(android.R.color.holo_orange_light));
        break;
    case 1:
        description.setText("active participant");
        icon.setBackgroundColor(context.getResources().getColor(android.R.color.holo_green_light));
        break;
    default:
        description.setText("participant with unknown state");
        icon.setBackgroundColor(context.getResources().getColor(android.R.color.holo_red_light));
        break;
    }
}

From source file:org.wdd.app.android.catgirl.views.ActionSheet.java

private void createItems() {
    String[] titles = getOtherButtonTitles();
    if (titles != null) {
        for (int i = 0; i < titles.length; i++) {
            Button bt = new Button(getContext());
            bt.setClickable(true);// w  w  w .j a  v a  2 s .c  o  m
            bt.setId(CANCEL_BUTTON_ID + i + 1);
            bt.setOnClickListener(this);
            bt.setBackgroundResource(R.drawable.common_list_item_bg);
            bt.setText(titles[i]);
            bt.setTextColor(Color.parseColor("#1E82FF"));
            bt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
            bt.setGravity(Gravity.CENTER);
            ViewCompat.setElevation(bt, 0);
            mPanel.addView(bt, new LayoutParams(LayoutParams.MATCH_PARENT, dp2px(getContext(), 45)));

            if (i < titles.length - 1) {
                ImageView line = new ImageView(getContext());
                line.setBackgroundColor(Color.parseColor("#cccccc"));
                mPanel.addView(line, new LayoutParams(LayoutParams.MATCH_PARENT, 1));
            }
        }
    }
    Button bt = new Button(getContext());
    bt.setClickable(true);
    bt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    bt.setId(ActionSheet.CANCEL_BUTTON_ID);
    bt.setBackgroundResource(R.drawable.common_list_item_bg);
    bt.setText(getCancelButtonTitle());
    bt.setTextColor(Color.parseColor("#1E82FF"));
    bt.setOnClickListener(this);
    ViewCompat.setElevation(bt, 0);
    ViewCompat.setTranslationZ(bt, 0);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, dp2px(getContext(), 45));
    bt.setGravity(Gravity.CENTER);
    params.topMargin = dp2px(getContext(), 6);
    mPanel.addView(bt, params);

    mPanel.setBackgroundColor(Color.TRANSPARENT);
    int padding = dp2px(getContext(), 6);
    mPanel.setPadding(padding, padding, padding, padding);
}

From source file:com.github.omadahealth.slidepager.lib.views.SlideChartView.java

/**
 * Init the {@link android.graphics.Color} of the {@link #mChartBarList}
 *//*from   w  ww.j  a va  2 s .co m*/
private void initBarColorsAndSize() {
    for (ImageView imageView : mChartBarList) {
        imageView.setBackgroundColor(mChartBarColor);
        if (imageView.getId() != R.id.progress_bottom_axis) {
            imageView.setMinimumHeight((int) (mChartBarSize / 2.0f));
        }
    }
}