Java Code Examples for android.support.v7.widget.CardView#setCardBackgroundColor()

The following examples show how to use android.support.v7.widget.CardView#setCardBackgroundColor() . 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: MonthFragmentAdapter.java    From Birdays with Apache License 2.0 6 votes vote down vote up
private void changeCardViewBackgroundColor(long date, CardView cardView, TextView textView) {
    String daysLeft = Utils.daysLeft(context, date);
    if (Utils.isBirthdayPassed(date)) {
        textView.setVisibility(View.GONE);
        cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.cardview_background));
    } else {
        textView.setVisibility(View.VISIBLE);
        String today = context.getString(R.string.today);
        if (daysLeft.equals(today)) {
            cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.cardview_birthday));
            textView.setText(today);
        } else {
            cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.cardview_background));
            String summary = context.getString(R.string.days_left) + ": " + daysLeft;
            textView.setText(summary);
        }
    }
}
 
Example 2
Source File: RhythmAdapter.java    From NBAPlus with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    RelativeLayout relativeLayout = (RelativeLayout) this.mInflater.inflate(R.layout.adapter_rhythm_icon, null);

    //设置item布局的大小以及Y轴的位置
    relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams((int) itemWidth, mContext.getResources().getDimensionPixelSize(R.dimen.rhythm_item_height)));
    relativeLayout.setTranslationY(itemWidth*3/7);

    //设置第二层RelativeLayout布局的宽和高
    RelativeLayout childRelativeLayout = (RelativeLayout) relativeLayout.getChildAt(0);
    CardView cardRhythm = (CardView)relativeLayout.findViewById(R.id.card_rhythm);
    TextView statName=(TextView)relativeLayout.findViewById(R.id.stat_name);
    cardRhythm.setCardBackgroundColor(mColorList[position]);
    statName.setText(sStatNames[position]);
    int relativeLayoutWidth = (int) itemWidth - 2 * mContext.getResources().getDimensionPixelSize(R.dimen.rhythm_icon_margin);
    childRelativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(relativeLayoutWidth, mContext.getResources().getDimensionPixelSize(R.dimen.rhythm_item_height) - 2 * mContext.getResources().getDimensionPixelSize(R.dimen.rhythm_icon_margin)));
    return relativeLayout;
}
 
Example 3
Source File: ReviewListAdapter.java    From AndroidReview with GNU General Public License v3.0 5 votes vote down vote up
private void cardViewSetBackgroundColor(Point point, CardView cardView) {
    switch (point.getColor()) {
        case NO_CONTENT:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.carview_no_content));
            break;
        case BROWN:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.brown_500));
            break;
        case DEEP_ORANGE:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.deep_orange_900));
            break;
        case ORANGE:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.orange_900));
            break;
        case GREEN:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.green));
            break;
        case LIGHT_BLUE:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.light_blue_900));
            break;
        case RED:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.red_900));
            break;
        case PINK:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.pink_600));
            break;
        case PURPLE:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.purple_800));
            break;
        default:
            cardView.setCardBackgroundColor(mContext.getResources().getColor(R.color.theme_color_level2));
            break;
    }
}
 
Example 4
Source File: InfoRecyclerViewAdapter.java    From Camera-Roll-Android-App with Apache License 2.0 5 votes vote down vote up
private void setColor(CardView card, TextView text, int color) {
    if (Color.alpha(color) == 0) {
        //color not found
        card.setVisibility(View.GONE);
        return;
    }

    card.setCardBackgroundColor(color);
    text.setTextColor(getTextColor(text.getContext(), color));
    String colorHex = String.format("#%06X", (0xFFFFFF & color));
    text.setText(colorHex);

    card.setTag(colorHex);
    card.setOnClickListener(onClickListener);
}
 
Example 5
Source File: ExploreSelectedTitleListAdapter.java    From C9MJ with Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(BaseViewHolder viewHolder, String title) {
    viewHolder.setText(R.id.tv_title, title)
            .setTextColor(R.id.tv_title, ContextCompat.getColor(mContext, R.color.color_icons))
            .addOnClickListener(R.id.cardview);
    CardView cardView = viewHolder.getView(R.id.cardview);
    cardView.setCardBackgroundColor(ContextCompat.getColor(mContext, R.color.color_primary));
}
 
Example 6
Source File: ProductsItemViewHolder.java    From privacy-friendly-shopping-list with Apache License 2.0 5 votes vote down vote up
private void updateVisibilityFormat(ProductItem item)
{
    Resources resources = cache.getActivity().getResources();
    TextView productNameTextView = productItemCache.getProductNameTextView();
    TextView productQuantityTextView = productItemCache.getQuantityTextView();
    TextView quantityTextView = productItemCache.getQuantityTextView();
    CardView productCard = productItemCache.getProductCard();
    AppCompatCheckBox checkbox = (AppCompatCheckBox) productItemCache.getCheckbox();

    if ( item.isChecked() )
    {
        int grey = resources.getColor(R.color.middlegrey);
        productCard.setCardBackgroundColor(resources.getColor(R.color.transparent));
        checkbox.setSupportButtonTintList(ColorStateList.valueOf(resources.getColor(R.color.middleblue)));
        productNameTextView.setTextColor(grey);
        quantityTextView.setTextColor(grey);
        productNameTextView.setPaintFlags(productNameTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
        productQuantityTextView.setPaintFlags(productQuantityTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    }
    else
    {
        int black = resources.getColor(R.color.black);
        productCard.setCardBackgroundColor(resources.getColor(R.color.white));
        checkbox.setSupportButtonTintList(ColorStateList.valueOf(resources.getColor(R.color.colorAccent)));
        productNameTextView.setTextColor(black);
        quantityTextView.setTextColor(black);
        productNameTextView.setPaintFlags(productNameTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
        productQuantityTextView.setPaintFlags(productQuantityTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
    }

}
 
Example 7
Source File: GroupPopupView.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
private void init() {
    if (isInEditMode()) {
        return;
    }
    _popupCard = (CardView) LayoutInflater.from(getContext()).inflate(R.layout.view_group_popup, this, false);
    // set the CardView color
    int color = Setup.appSettings().getDesktopFolderColor();
    int alpha = Color.alpha(color);
    _popupCard.setCardBackgroundColor(color);
    // remove elevation if CardView's background is transparent to avoid weird shadows because CardView does not support transparent backgrounds
    if (alpha == 0) {
        _popupCard.setCardElevation(0f);
    }
    _cellContainer = _popupCard.findViewById(R.id.group);

    bringToFront();

    setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (_dismissListener != null) {
                _dismissListener.onDismiss();
            }
            collapse();
        }
    });

    addView(_popupCard);
    _popupCard.setVisibility(View.INVISIBLE);
    setVisibility(View.INVISIBLE);

    _textViewGroupName = _popupCard.findViewById(R.id.group_popup_label);
}
 
Example 8
Source File: ThemeStoriesFragment.java    From ZhihuDaily with Apache License 2.0 5 votes vote down vote up
@Override
public void refreshUI() {
    TypedValue itemStoryTextColor = new TypedValue();
    TypedValue itemStoryBackground = new TypedValue();
    TypedValue windowBackground = new TypedValue();
    Resources.Theme theme = getActivity().getTheme();
    theme.resolveAttribute(R.attr.item_story_text_color, itemStoryTextColor, true);
    theme.resolveAttribute(R.attr.item_story_background_color, itemStoryBackground, true);
    theme.resolveAttribute(R.attr.windowBackground, windowBackground, true);

    Resources resources = getResources();
    View window=((ViewGroup) getActivity().getWindow().getDecorView());
    window.setBackgroundColor(resources.getColor(windowBackground.resourceId));
    int childCount = recyclerView.getChildCount();
    int firstVisible = mLinearLayoutManager.findFirstVisibleItemPosition();
    for (int childIndex = 0; childIndex < childCount; childIndex++) {
        int viewType = mAdapter.getItemViewType(childIndex + firstVisible);
        switch (viewType) {
            case ThemeStoriesAdapter.Type.TYPE_HEADER:
                break;
            case ThemeStoriesAdapter.Type.TYPE_AVATARS:
                AvatarsView avatarsView = (AvatarsView) recyclerView.getChildAt(childIndex);
                avatarsView.setBackgroundColor(resources.getColor(windowBackground.resourceId));
                break;
            case ThemeStoriesAdapter.Type.TYPE_ITEM:
                CardView cardView = (CardView) recyclerView.getChildAt(childIndex);
                cardView.setCardBackgroundColor(resources.getColor(itemStoryBackground.resourceId));
                TextView title = (TextView) cardView.findViewById(R.id.title);
                title.setTextColor(resources.getColor(itemStoryTextColor.resourceId));
                break;
        }
    }
    invalidateCacheItem();
}
 
Example 9
Source File: AcNavigationRvAdapter.java    From BlueBoard with Apache License 2.0 5 votes vote down vote up
private void setButtonInfo(ImageView imgButton, TextView tvButton, CardView cvButton, int drawable, int color, final String partitionType) {
    imgButton.setBackgroundResource(drawable);
    tvButton.setText(partitionType);
    cvButton.setCardBackgroundColor(MyApplication.getInstance().getResources().getColor(color));
    cvButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mOnClickListener.onClick(v, partitionType);
        }
    });
}
 
Example 10
Source File: FabSpeedDial.java    From fab-speed-dial with Apache License 2.0 4 votes vote down vote up
private View createFabMenuItem(MenuItem menuItem) {
    ViewGroup fabMenuItem = (ViewGroup) LayoutInflater.from(getContext())
            .inflate(getMenuItemLayoutId(), this, false);

    FloatingActionButton miniFab = (FloatingActionButton) fabMenuItem.findViewById(R.id.mini_fab);
    CardView cardView = (CardView) fabMenuItem.findViewById(R.id.card_view);
    TextView titleView = (TextView) fabMenuItem.findViewById(R.id.title_view);

    fabMenuItemMap.put(miniFab, menuItem);
    cardViewMenuItemMap.put(cardView, menuItem);

    miniFab.setImageDrawable(menuItem.getIcon());
    miniFab.setOnClickListener(this);
    cardView.setOnClickListener(this);

    ViewCompat.setAlpha(miniFab, 0f);
    ViewCompat.setAlpha(cardView, 0f);

    final CharSequence title = menuItem.getTitle();
    if (!TextUtils.isEmpty(title) && miniFabTitlesEnabled) {
        cardView.setCardBackgroundColor(miniFabTitleBackgroundTint.getDefaultColor());
        titleView.setText(title);
        titleView.setTypeface(null, Typeface.BOLD);
        titleView.setTextColor(miniFabTitleTextColor);

        if (miniFabTitleTextColorArray != null) {
            titleView.setTextColor(ContextCompat.getColorStateList(getContext(),
                    miniFabTitleTextColorArray[menuItem.getOrder()]));
        }
    } else {
        fabMenuItem.removeView(cardView);
    }

    miniFab.setBackgroundTintList(miniFabBackgroundTint);

    if (miniFabBackgroundTintArray != null) {
        miniFab.setBackgroundTintList(ContextCompat.getColorStateList(getContext(),
                miniFabBackgroundTintArray[menuItem.getOrder()]));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        miniFab.setImageTintList(miniFabDrawableTint);
    }

    return fabMenuItem;
}
 
Example 11
Source File: ProcessViewer.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      rootView = inflater.inflate(R.layout.processparent, container, false);
      setRetainInstance(false);
setStyle(DialogFragment.STYLE_NO_TITLE, 0);
      mainActivity = (ExplorerActivity) getActivity();

      ColorPreference colorPreference = mainActivity.getColorPreference();
accentColor = colorPreference.getColor(ColorUsage.ACCENT);
      primaryColor = colorPreference.getColor(ColorUsage.PRIMARY);
      if (mainActivity.getAppTheme().equals(AppTheme.DARK))
          rootView.setBackgroundResource((R.color.cardView_background));
      //mainActivity.updateViews(new ColorDrawable(primaryColor));
      //mainActivity.getAppbar().setTitle(getResources().getString(R.string.process_viewer));
      //mainActivity.floatingActionButton.hideMenuButton(true);
      //sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mainActivity);
      //mainActivity.supportInvalidateOptionsMenu();

      mCardView = (CardView) rootView.findViewById(R.id.card_view);

      mLineChart = (LineChart) rootView.findViewById(R.id.progress_chart);
      mProgressImage = (ImageView) rootView.findViewById(R.id.progress_image);
      mCancelButton = (ImageButton) rootView.findViewById(R.id.delete_button);
      mProgressTypeText = (TextView) rootView.findViewById(R.id.text_view_progress_type);
      mProgressFileNameText = (TextView) rootView.findViewById(R.id.text_view_progress_file_name);
      mProgressBytesText = (TextView) rootView.findViewById(R.id.text_view_progress_bytes);
      mProgressFileText = (TextView) rootView.findViewById(R.id.text_view_progress_file);
      mProgressSpeedText = (TextView) rootView.findViewById(R.id.text_view_progress_speed);
      mProgressTimer = (TextView) rootView.findViewById(R.id.text_view_progress_timer);
mProgressTypeText.setTextColor(accentColor);
      if (!copyCancelled) {
	mCancelButton.setEnabled(true);
}
if (mainActivity.getAppTheme().equals(AppTheme.DARK)) {
          mCancelButton.setImageResource(R.drawable.ic_action_cancel);
          mCardView.setCardBackgroundColor(Utils.getColor(getContext(), R.color.cardView_foreground));
          mCardView.setCardElevation(0f);
      }

      return rootView;
  }
 
Example 12
Source File: CardViewHandler.java    From NightOwl with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(@NonNull View view, @NonNull Object value) {
    CardView cardView = (CardView) view;
    cardView.setCardBackgroundColor((Integer) value);
}
 
Example 13
Source File: MainActivity.java    From AndroidBasicProject with MIT License 4 votes vote down vote up
@Override public void onUpdate(BaseAdapterHelper helper, Demo item, int position) {
    final CardView cardView = helper.getView(R.id.main_item_cardview);
    cardView.setCardBackgroundColor(item.bgColor);
    helper.setText(R.id.main_item_tv, item.title);
}
 
Example 14
Source File: MainActivity.java    From BaseProject with MIT License 4 votes vote down vote up
@Override
public void onUpdate(BaseAdapterHelper helper, Demo item, int position) {
    final CardView cardView = helper.getView(R.id.main_item_cardview);
    cardView.setCardBackgroundColor(item.bgColor);
    helper.setText(R.id.main_item_tv, item.title);
}
 
Example 15
Source File: PopMenuView.java    From PopMenuLayout with MIT License 4 votes vote down vote up
private void init(Context context){
    mMenus = new ArrayList<MenuBean>();
    mMenuAdapter = new MenuAdapter(mContext, mMenus, mLayoutManagerOrientation);
    mMenuAdapter.setMenuWidth(mWidth);
    mMenuAdapter.setTextPaddingLeft(mMenuTextPaddingLeft);
    mMenuAdapter.setTextPaddingBottom(mMenuTextPaddingBottom);
    mMenuAdapter.setTextPaddingRight(mMenuTextPaddingRight);
    mMenuAdapter.setTextPaddingTop(mMenuTextPaddingTop);
    mMenuAdapter.setDividerDp(mMenuDividerDp);
    mMenuAdapter.setDividerColor(mDividerColor);
    mMenuAdapter.setExpandableIcon(mExpandableIcon);
    mMenuAdapter.setMenuTextColor(mMenuTextColor);
    mMenuAdapter.setHorizontalMenuBackgroundRes(mHorizontalMenuBackgroundRes);
    mMenuAdapter.setVerticalMenuBackgroundRes(mVerticalMenuBackgroundRes);
    mMenuAdapter.setMenuTextSize(mMenuTextSize);
    mMenuAdapter.setOnMenuClickListener(new OnMenuClickListener() {
        @Override
        public void onMenuClick(int level1Index, int level2Index, int level3Index) {
            dealMenuClickEvent(level1Index, level2Index, level3Index);
        }
    });
    mLayoutManager = new LinearLayoutManager(mContext);
    mLayoutManager.setOrientation(mLayoutManagerOrientation);

    mRootView = LayoutInflater.from(mContext).inflate(R.layout.view_menu_container, null);
    mCardView = (CardView) mRootView.findViewById(R.id.cardView);
    mCardView.setCardBackgroundColor(mMenuLayoutBgColor);
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mCardView.getLayoutParams();
    if (mWidth != -1){
        params.width = mWidth;
    }
    if (mHeight != -1){
        params.height = mHeight;
    }
    mCardView.setLayoutParams(params);

    mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recyclerView);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mMenuAdapter);

    setContentView(mRootView);
    setWidth(RelativeLayout.LayoutParams.WRAP_CONTENT);
    setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
    setFocusable(true);
    setAnimationStyle(mAnimStyle);
    setBackgroundDrawable(new ColorDrawable(0x00000000));
}
 
Example 16
Source File: CardsFragment.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private void addEmptyCard() {
    Context context = getContext();
    int dp8 = RaadCommonUtils.getPx(8, context);
    int dp16 = RaadCommonUtils.getPx(16, context);

    int cardHeight = BankCardView.getDefaultCardHeight(getContext());

    CardView cardView = new CardView(context);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, cardHeight);
    params.setMargins(dp16, 0, dp16, dp16);
    cardView.setLayoutParams(params);
    if (WalletActivity.isDarkTheme) {
        cardView.setCardBackgroundColor(Color.parseColor(WalletActivity.backgroundTheme_2));
    } else {
        cardView.setCardBackgroundColor(Color.parseColor(WalletActivity.backgroundTheme));
    }

    cardView.setPreventCornerOverlap(false);
    cardView.setCardElevation(RaadCommonUtils.getPx(6, context));
    cardView.setRadius(RaadCommonUtils.getPx(8, context));
    cardsLayout.addView(cardView);
    viewItems.add(cardView);

    TextView textView = new TextView(context);
    CardView.LayoutParams textViewParams = new CardView.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    textViewParams.gravity = Gravity.CENTER;
    textView.setLayoutParams(textViewParams);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(Color.parseColor(WalletActivity.textTitleTheme));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
    textView.setTypeface(Typefaces.get(context, Typefaces.IRAN_YEKAN_REGULAR));
    textView.setText(R.string.click_here_for_adding_card);
    cardView.addView(textView);

    cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ((NavigationBarActivity) getActivity()).pushFullFragment(
                    new AddCardFragment(), "AddCardFragment");
        }
    });
}
 
Example 17
Source File: ExploreFragment.java    From C9MJ with Apache License 2.0 4 votes vote down vote up
@Override
public void onItemDragEnd(RecyclerView.ViewHolder viewHolder, int pos) {
    BaseViewHolder holder = (BaseViewHolder) viewHolder;
    CardView cardView = holder.getView(R.id.cardview);
    cardView.setCardBackgroundColor(ContextCompat.getColor(context, R.color.color_primary));
}
 
Example 18
Source File: Adapter.java    From Android-Material-Icons with Apache License 2.0 4 votes vote down vote up
private void setCardViewSelected(CardView cardView, boolean selected) {
    cardView.setCardBackgroundColor(selected ? mSelectedCardColor : Color.WHITE);
}
 
Example 19
Source File: FancyWalkthroughFragment.java    From FancyWalkthrough-Android with Apache License 2.0 4 votes vote down vote up
@SuppressLint("ResourceAsColor")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    Bundle bundle = getArguments();

    title = bundle.getString(FANCY_PAGE_TITLE, null);
    titleResId = bundle.getInt(FANCY_PAGE_TITLE_RES_ID, 0);
    titleColor = bundle.getInt(FANCY_PAGE_TITLE_COLOR, 0);
    titleTextSize = bundle.getFloat(FANCY_PAGE_TITLE_TEXT_SIZE, 0f);
    description = bundle.getString(FANCY_PAGE_DESCRIPTION, null);
    descriptionResId = bundle.getInt(FANCY_PAGE_DESCRIPTION_RES_ID, 0);
    descriptionColor = bundle.getInt(FANCY_PAGE_DESCRIPTION_COLOR, 0);
    descriptionTextSize = bundle.getFloat(FANCY_PAGE_DESCRIPTION_TEXT_SIZE, 0f);
    imageResId = bundle.getInt(FANCY_PAGE_IMAGE_RES_ID, 0);
    backgroundColor = bundle.getInt(FANCY_PAGE_BACKGROUND_COLOR, 0);
    iconWidth = bundle.getInt(FANCY_PAGE_ICON_WIDTH, (int) dpToPixels(128, getActivity()));
    iconHeight = bundle.getInt(FANCY_PAGE_ICON_HEIGHT, (int) dpToPixels(128, getActivity()));
    marginTop = bundle.getInt(FANCY_PAGE_MARGIN_TOP, (int) dpToPixels(80, getActivity()));
    marginBottom = bundle.getInt(FANCY_PAGE_MARGIN_BOTTOM, (int) dpToPixels(0, getActivity()));
    marginLeft = bundle.getInt(FANCY_PAGE_MARGIN_LEFT, (int) dpToPixels(0, getActivity()));
    marginRight = bundle.getInt(FANCY_PAGE_MARGIN_RIGHT, (int) dpToPixels(0, getActivity()));

    view = inflater.inflate(R.layout.fragment_ahoy, container, false);
    ivOnboarderImage = (ImageView) view.findViewById(R.id.iv_image);
    tvOnboarderTitle = (TextView) view.findViewById(R.id.tv_title);
    tvOnboarderDescription = (TextView) view.findViewById(R.id.tv_description);
    cardView = (CardView) view.findViewById(R.id.cv_cardview);
    view1 = (View) view.findViewById(R.id.view1);


    if (title != null) {
        tvOnboarderTitle.setText(title);
    }

    if (titleResId != 0) {
        tvOnboarderTitle.setText(getResources().getString(titleResId));
    }

    if (description != null) {
        tvOnboarderDescription.setText(description);
    }

    if (descriptionResId != 0) {
        tvOnboarderDescription.setText(getResources().getString(descriptionResId));
    }

    if (titleColor != 0) {
        tvOnboarderTitle.setTextColor(ContextCompat.getColor(getActivity(), titleColor));
    }

    if (descriptionColor != 0) {
        tvOnboarderDescription.setTextColor(ContextCompat.getColor(getActivity(), descriptionColor));
    }

    if (imageResId != 0) {
           ivOnboarderImage.setImageDrawable(ContextCompat.getDrawable(getActivity(), imageResId));
    }

    if (titleTextSize != 0f) {
        tvOnboarderTitle.setTextSize(titleTextSize);
    }

    if (descriptionTextSize != 0f) {
        tvOnboarderDescription.setTextSize(descriptionTextSize);
    }

    if (backgroundColor != 0) {
        cardView.setCardBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorTransparent));
        GradientDrawable bgShape = (GradientDrawable) view1.getBackground();
        bgShape.setColor(ContextCompat.getColor(getActivity(), backgroundColor));

    }

    if (iconWidth != 0 && iconHeight != 0) {
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(iconWidth, iconHeight);
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        layoutParams.setMargins(marginLeft, marginTop, marginRight, marginBottom);
        ivOnboarderImage.setLayoutParams(layoutParams);
    }

    return view;
}
 
Example 20
Source File: CanDialog.java    From CanDialog with Apache License 2.0 3 votes vote down vote up
public void setBackgroundColor(int color) {

        CardView cardView = (CardView) findViewById(R.id.card);
        cardView.setCardBackgroundColor(color);


    }