android.support.v7.widget.CardView.setForeground()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中android.support.v7.widget.CardView.setForeground()方法的一些代码示例,展示了CardView.setForeground()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CardView.setForeground()方法的具体详情如下:
包路径:android.support.v7.widget.CardView
类名称:CardView
方法名:setForeground

CardView.setForeground介绍

暂无

代码示例

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void onBindViewHolder(ClickableViewHolder holder, int position) {
  if (holder instanceof ItemViewHolder) {
    ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
    BangumiDetailsInfo.ResultBean.SeasonsBean seasonsBean = seasons.get(position);
    itemViewHolder.mSeasons.setText(seasonsBean.getTitle());
    if (position == layoutPosition) {
      itemViewHolder.mCardView.setForeground(
          getContext().getResources().getDrawable(R.drawable.bg_selection));
      itemViewHolder.mSeasons.setTextColor(
          getContext().getResources().getColor(R.color.colorPrimary));
    } else {
      itemViewHolder.mCardView.setForeground(
          getContext().getResources().getDrawable(R.drawable.bg_normal));
      itemViewHolder.mSeasons.setTextColor(
          getContext().getResources().getColor(R.color.font_normal));
    }
  }
  super.onBindViewHolder(holder, position);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void onBindViewHolder(ClickableViewHolder holder, int position) {
  if (holder instanceof ItemViewHolder) {
    ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
    BangumiDetailsInfo.ResultBean.EpisodesBean episodesBean = episodes.get(position);
    itemViewHolder.mIndex.setText("第 " + episodesBean.getIndex() + " 话");
    itemViewHolder.mTitle.setText(episodesBean.getIndex_title());
    if (position == layoutPosition) {
      itemViewHolder.mCardView.setForeground(
          getContext().getResources().getDrawable(R.drawable.bg_selection));
      itemViewHolder.mTitle.setTextColor(
          getContext().getResources().getColor(R.color.colorPrimary));
      itemViewHolder.mIndex.setTextColor(
          getContext().getResources().getColor(R.color.colorPrimary));
    } else {
      itemViewHolder.mCardView.setForeground(
          getContext().getResources().getDrawable(R.drawable.bg_normal));
      itemViewHolder.mTitle.setTextColor(
          getContext().getResources().getColor(R.color.black_alpha_45));
      itemViewHolder.mIndex.setTextColor(
          getContext().getResources().getColor(R.color.font_normal));
    }
  }
  super.onBindViewHolder(holder, position);
}

代码示例来源:origin: woxblom/DragListView

@Override
public void onBindDragView(View clickedView, View dragView) {
  CharSequence text = ((TextView) clickedView.findViewById(R.id.text)).getText();
  ((TextView) dragView.findViewById(R.id.text)).setText(text);
  CardView dragCard = dragView.findViewById(R.id.card);
  CardView clickedCard = clickedView.findViewById(R.id.card);
  dragCard.setMaxCardElevation(40);
  dragCard.setCardElevation(clickedCard.getCardElevation());
  // I know the dragView is a FrameLayout and that is why I can use setForeground below api level 23
  dragCard.setForeground(clickedView.getResources().getDrawable(R.drawable.card_view_drag_foreground));
}

代码示例来源:origin: WeDevelopTeam/HeroVideo-master

@Override
public void onBindViewHolder(ClickableViewHolder holder, int position) {
  if (holder instanceof ItemViewHolder) {
    ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
    String url = urls.get(position);
    itemViewHolder.mIndex.setText("" +position);
    if (position == layoutPosition) {
      itemViewHolder.mCardView.setForeground(getContext().getResources().getDrawable(R.drawable.bg_selection));
      itemViewHolder.mIndex.setTextColor(getContext().getResources().getColor(R.color.text_primary_color));
    } else {
      itemViewHolder.mCardView.setForeground(getContext().getResources().getDrawable(R.drawable.bg_normal));
      itemViewHolder.mIndex.setTextColor(getContext().getResources().getColor(R.color.font_normal));
    }
  }
  super.onBindViewHolder(holder, position);
}

代码示例来源:origin: WeDevelopTeam/HeroVideo-master

@Override
public void onBindViewHolder(ClickableViewHolder holder, int position)
{
  if (holder instanceof ItemViewHolder)
  {
    ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
    BangumiDetailsInfo.ResultBean.SeasonsBean seasonsBean = seasons.get(position);
    itemViewHolder.mSeasons.setText(seasonsBean.getTitle());
    if (position == layoutPosition)
    {
      itemViewHolder.mCardView.setForeground(getContext().getResources().getDrawable(R.drawable.bg_selection));
      itemViewHolder.mSeasons.setTextColor(getContext().getResources().getColor(R.color.text_primary_color));
    } else
    {
      itemViewHolder.mCardView.setForeground(getContext().getResources().getDrawable(R.drawable.bg_normal));
      itemViewHolder.mSeasons.setTextColor(getContext().getResources().getColor(R.color.font_normal));
    }
  }
  super.onBindViewHolder(holder, position);
}

代码示例来源:origin: WeDevelopTeam/HeroVideo-master

@Override
public void onBindViewHolder(ClickableViewHolder holder, int position)
{
  if (holder instanceof ItemViewHolder)
  {
    ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
    BangumiDetailsInfo.ResultBean.EpisodesBean episodesBean = episodes.get(position);
    itemViewHolder.mIndex.setText("第 " + episodesBean.getIndex() + " 话");
    itemViewHolder.mTitle.setText(episodesBean.getIndex_title());
    if (position == layoutPosition)
    {
      itemViewHolder.mCardView.setForeground(getContext().getResources().getDrawable(R.drawable.bg_selection));
      itemViewHolder.mTitle.setTextColor(getContext().getResources().getColor(R.color.text_primary_color));
      itemViewHolder.mIndex.setTextColor(getContext().getResources().getColor(R.color.text_primary_color));
    } else
    {
      itemViewHolder.mCardView.setForeground(getContext().getResources().getDrawable(R.drawable.bg_normal));
      itemViewHolder.mTitle.setTextColor(getContext().getResources().getColor(R.color.black_alpha_45));
      itemViewHolder.mIndex.setTextColor(getContext().getResources().getColor(R.color.font_normal));
    }
  }
  super.onBindViewHolder(holder, position);
}

代码示例来源:origin: ywwynm/EverythingDone

public static void setRippleColorForCardView(CardView cardView, int color) {
  if (DeviceUtil.hasLollipopApi()) {
    RippleDrawable rp = (RippleDrawable) cardView.getForeground();
    rp.setColor(ColorStateList.valueOf(color));
  } else {
    if (sSldMap == null) {
      sSldMap = new SparseArray<>();
    }
    StateListDrawable sld = sSldMap.get(color);
    if (sld == null) {
      sld = new StateListDrawable();
      sld.addState(new int[] { android.R.attr.state_pressed },
          new ColorDrawable(color));
      sld.addState(new int[]{-android.R.attr.state_pressed},
          new ColorDrawable(Color.TRANSPARENT));
      sSldMap.put(color, sld);
    }
    cardView.setForeground(sld);
  }
}

代码示例来源:origin: materialos/android-icon-pack

@Override
public void onBindViewHolder(RequestVH holder, int position) {
  super.onBindViewHolder(holder, position);
  if (position == 0) {
    final Context c = holder.itemView.getContext();
    if (mAllowRequest == RequestLimiter.WAIT) {
      final String msg = c.getString(R.string.request_limited,
          RequestLimiter.get(c).remainingIntervalString());
      holder.title.setText(msg);
    } else if (mAllowRequest == RequestLimiter.NO_LIMIT) {
      holder.title.setText(R.string.tap_to_select_app);
    } else {
      holder.title.setText(c.getResources().getString(R.string.tap_to_select_app_withremaining, mAllowRequest));
    }
    final int bgColor = DialogUtils.resolveColor(holder.itemView.getContext(), R.attr.window_background_cards);
    final int titleColor = TintUtils.isColorLight(bgColor) ? Color.BLACK : Color.WHITE;
    holder.title.setTextColor(TintUtils.adjustAlpha(titleColor, 0.5f));
    return;
  }
  final App app = mApps.get(position - 1);
  app.loadIcon(holder.image);
  holder.title.setText(app.getName());
  if (holder.card != null) {
    holder.card.setForeground(Utils.createCardSelector(holder.itemView.getContext()));
    holder.card.setActivated(isIndexSelected(position));
  }
}

相关文章