下面列出了android.widget.FrameLayout#setForeground ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Set the theme: {@link #THEME_DARK} or {@link #THEME_LIGHT}.
* Default is {@link #THEME_DARK}. */
public void setTheme(int theme) {
if (mTheme != theme && (theme == THEME_DARK || theme == THEME_LIGHT)) {
mTheme = theme;
TextView messageView = (TextView) findViewById(android.R.id.message);
if (null != messageView) messageView.setTextColor(((mTheme == THEME_DARK) ? Color.WHITE : Color.BLACK));
mLayout.setBackgroundResource(mTheme);
FrameLayout contentContainer = (FrameLayout) findViewById(R.id.contentPanel);
if (null != contentContainer) {
switch (mTheme) {
case THEME_DARK:
contentContainer.setForeground(
getResources().getDrawable(R.drawable.ab_solid_shadow_holo));
break;
case THEME_LIGHT:
contentContainer.setForeground(null);
break;
}
}
}
}
/** Set the theme: {@link #THEME_DARK} or {@link #THEME_LIGHT}.
* Default is {@link #THEME_DARK}. */
public void setTheme(int theme) {
if (mTheme != theme && (theme == THEME_DARK || theme == THEME_LIGHT)) {
mTheme = theme;
TextView messageView = (TextView) findViewById(android.R.id.message);
if (null != messageView) messageView.setTextColor(((mTheme == THEME_DARK) ? Color.WHITE : Color.BLACK));
mLayout.setBackgroundResource(mTheme);
FrameLayout contentContainer = (FrameLayout) findViewById(R.id.contentPanel);
if (null != contentContainer) {
switch (mTheme) {
case THEME_DARK:
contentContainer.setForeground(
getResources().getDrawable(R.drawable.ab_solid_shadow_holo));
break;
case THEME_LIGHT:
contentContainer.setForeground(null);
break;
}
}
}
}
public CellHolder(LayoutInflater inflater) {
fl = (FrameLayout) inflater.inflate(
R.layout.list_item_top_grid_item, null);
iv = (ImageView) fl.findViewById(R.id.iv);
ivAnimated = (ImageView) fl
.findViewById(R.id.iv_animated);
flContainer = (FrameLayout) fl.findViewById(R.id.fl);
Drawable foreground = inflater.getContext().getResources()
.getDrawable(R.drawable.grid_photo_overlay);
foreground.getPadding(paddingRect);
fl.setForeground(foreground);
fl.setPadding(paddingRect.left, paddingRect.top, paddingRect.right,
paddingRect.bottom);
fl.setForegroundGravity(Gravity.FILL);
}
@Override
public void set(FrameLayout layout, Integer value) {
if (layout.getForeground() instanceof ColorDrawable) {
((ColorDrawable) layout.getForeground().mutate()).setColor(value);
} else {
layout.setForeground(new ColorDrawable(value));
}
}
private void setBackgroundColor(RecyclerView.ViewHolder holder, int position) {
try {
// set blue back ground for selected file
FrameLayout layout = (FrameLayout) holder.itemView.findViewById(R.id.smsl_fl_contain_main);
if (SelectedList.indexOf(mList.get(position).messageId) >= 0) {
layout.setForeground(new ColorDrawable(Color.parseColor("#99AADFF7")));
} else {
layout.setForeground(new ColorDrawable(Color.TRANSPARENT));
}
} catch (Exception e) {
}
}
@Override
public void setValue(FrameLayout layout, int value) {
if (layout.getForeground() instanceof ColorDrawable) {
((ColorDrawable) layout.getForeground().mutate()).setColor(value);
} else {
layout.setForeground(new ColorDrawable(value));
}
}
public static void attachBadgeDrawable(
@NonNull BadgeDrawable badgeDrawable,
@NonNull View anchor,
@Nullable FrameLayout compatBadgeParent) {
setBadgeDrawableBounds(badgeDrawable, anchor, compatBadgeParent);
if (USE_COMPAT_PARENT) {
if (compatBadgeParent == null) {
throw new IllegalArgumentException("Trying to reference null compatBadgeParent");
}
compatBadgeParent.setForeground(badgeDrawable);
} else {
anchor.getOverlay().add(badgeDrawable);
}
}
public static void detachBadgeDrawable(
@Nullable BadgeDrawable badgeDrawable,
@NonNull View anchor,
@NonNull FrameLayout compatBadgeParent) {
if (badgeDrawable == null) {
return;
}
if (USE_COMPAT_PARENT) {
compatBadgeParent.setForeground(null);
} else {
anchor.getOverlay().remove(badgeDrawable);
}
}
@NonNull
@Override
public final ViewHolderWrapper<VH> onCreateViewHolder(@NonNull final ViewGroup parent,
final int viewType) {
VH viewHolder = wrappedAdapter.createViewHolder(parent, viewType);
Context context = parent.getContext();
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setForeground(ThemeUtil.getDrawable(context, R.attr.selectableItemBackground));
frameLayout.addView(viewHolder.itemView);
frameLayout.setLayoutParams(
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.WRAP_CONTENT));
return new ViewHolderWrapper<>(frameLayout, viewHolder);
}
private AttachmentHolder addNewAttachment() {
FrameLayout view = (FrameLayout) getLayoutInflater().inflate(R.layout.activity_posting_attachment,
attachmentContainer, false);
if (C.API_LOLLIPOP) {
float density = ResourceUtils.obtainDensity(this);
view.setForeground(new RoundedCornersDrawable((int) (2f * density), ResourceUtils.getColor(this,
android.R.attr.windowBackground)));
}
addAttachmentViewToContainer(view, attachments.size());
AttachmentHolder holder = new AttachmentHolder();
holder.view = view;
holder.fileName = view.findViewById(R.id.attachment_name);
holder.fileSize = view.findViewById(R.id.attachment_size);
holder.options = view.findViewById(R.id.attachment_options);
holder.imageView = view.findViewById(R.id.attachment_preview);
holder.imageView.setBackground(new TransparentTileDrawable(this, true));
holder.warningButton = view.findViewById(R.id.attachment_warning);
holder.warningButton.setOnClickListener(attachmentWarningListener);
holder.warningButton.setTag(holder);
holder.ratingButton = view.findViewById(R.id.attachment_rating);
holder.ratingButton.setOnClickListener(attachmentRatingListener);
holder.ratingButton.setTag(holder);
holder.removeButton = view.findViewById(R.id.attachment_remove);
holder.removeButton.setOnClickListener(attachmentRemoveListener);
holder.removeButton.setTag(holder);
holder.options.setOnClickListener(attachmentOptionsListener);
holder.options.setTag(holder);
attachments.add(holder);
invalidateOptionsMenu();
scrollView.postResizeComment();
return holder;
}
static void setWallpaperItemPaddingToZero(FrameLayout frameLayout) {
frameLayout.setPadding(0, 0, 0, 0);
frameLayout.setForeground(new ZeroPaddingDrawable(frameLayout.getForeground()));
}
public void setToolbar(View toolbar, FrameLayout toolbarDrawerInterlayerLayout) {
toolbarView = toolbar;
toolbarDrawerInterlayerLayout.setForeground(statusBarContentForeground);
addAdditionalView(toolbarDrawerInterlayerLayout, false);
}
static void setWallpaperItemPaddingToZero(FrameLayout frameLayout) {
frameLayout.setPadding(0, 0, 0, 0);
frameLayout.setForeground(new ZeroPaddingDrawable(frameLayout.getForeground()));
}
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = mViews[position];
if(convertView == null){
AnimatedScaleDrawable drawable = new AnimatedScaleDrawable(
parent.getContext().getResources().getDrawable(R.drawable.heart));
drawable.setInterpolator(new BounceInterpolator());
drawable.setInvertTransformation(true);
drawable.setDuration(500);
FrameLayout frame = (FrameLayout)LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_frame, parent, false);
if(position == 0){
// ProgressBar example
ProgressBar progress = (ProgressBar)LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_progress, frame, false);
progress.setIndeterminateDrawable(drawable);
frame.addView(progress);
}
else{
if(position == 1 || position == 2){
// Background drawable example
frame.setBackgroundDrawable(drawable);
if(position == 2){
drawable.setUseBounds(false);
}
}else{
// Foreground's with Gravity example
frame.setForeground(drawable);
frame.setForegroundGravity(mGravity[position - 3]);
}
// no need to call drawable.start() for ProgressBar widgets
drawable.start();
}
TextView textView = (TextView)frame.findViewById(R.id.text);
textView.setText(String.format("#%02d %s", position, mNames[position]));
convertView = frame;
}
return convertView;
}
/**
* Similar to {@link #decorate(View...)}, but decorates foregrounds instead of backgrounds of provided views
* (available only for {@link FrameLayout}), therefore drawing the overlay over the view’s content. Similarly to
* <code>decorate(View...)</code>, wraps and replaces existing foreground drawable with {@link RhythmDrawable}.
*
* @param views Frame layouts whose foregrounds should be decorated
* @see #decorate(View...)
*/
public void decorateForeground(FrameLayout... views) {
for (FrameLayout view : views) {
RhythmDrawable decoratingRhythmDrawable = makeDrawable();
decoratingRhythmDrawable.setDecorated(view.getForeground());
view.setForeground(decoratingRhythmDrawable);
}
}