android.view.View#setBackgroundDrawable ( )源码实例Demo

下面列出了android.view.View#setBackgroundDrawable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android-Skin   文件: BackgroundAttr.java
@Override
public void apply(View view) {
    if (view==null){
        return;
    }
    if (RES_TYPE_NAME_COLOR.equals(attrValueTypeName)) {
        view.setBackgroundColor(AndroidSkin.getInstance().getSkinColor(
                attrValueTypeName, attrValueRefName, attrValueRefId));
    } else if (RES_TYPE_NAME_DRAWABLE.equals(attrValueTypeName)) {
        Drawable bg = AndroidSkin.getInstance().getSkinDrawable(
                attrValueTypeName, attrValueRefName, attrValueRefId);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.setBackground(bg);
        } else {
            view.setBackgroundDrawable(bg);
        }
    }
    //LogUtils.d(TAG, "view apply ,id "+attrValueRefId+" " + attrValueTypeName+" "+attrValueRefName );
}
 
源代码2 项目: letv   文件: HotTabPageIndicator.java
public void setCurrentItem(int item) {
    if (this.mViewPager != null) {
        if (!(item == -1 || this.mSelectedTabIndex == item)) {
            this.mViewPager.setCurrentItem(item);
        }
        this.mSelectedTabIndex = item;
        int tabCount = this.mTabLayout.getChildCount();
        int i = 0;
        while (i < tabCount) {
            View child = this.mTabLayout.getChildAt(i);
            boolean isSelected = i == item;
            child.setSelected(isSelected);
            if (isSelected) {
                animateToTab(item);
                ((TabView) child).setTextColor(this.mContext.getResources().getColor(2131493202));
                child.setBackgroundResource(2130839011);
            } else {
                ((TabView) child).setTextColor(this.mContext.getResources().getColor(2131493237));
                child.setBackgroundDrawable(null);
            }
            i++;
        }
    }
}
 
源代码3 项目: UltimateAndroid   文件: Sections.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final int type = getItemViewType(position);

    View v = null;
    if (convertView != null) {
        Log.d("mobeta", "using convertView");
        v = convertView;
    } else if (type != SECTION_DIV) {
        Log.d("mobeta", "inflating normal item");
        v = mInflater.inflate(R.layout.drag_sort_listview_list_item_bg_handle, parent, false);
        v.setBackgroundDrawable(getBGDrawable(type));
    } else {
        Log.d("mobeta", "inflating section divider");
        v = mInflater.inflate(R.layout.drag_sort_listview_section_div, parent, false);
    }

    if (type != SECTION_DIV) {
        // bind data
        ((TextView) v).setText(mData.get(dataPosition(position)));
    }

    return v;
}
 
源代码4 项目: android-art-res   文件: MainActivity.java
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        // test transition
        View v = findViewById(R.id.test_transition);
        TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
        drawable.startTransition(1000);

        // test scale
        View testScale = findViewById(R.id.test_scale);
        ScaleDrawable testScaleDrawable = (ScaleDrawable) testScale.getBackground();
        testScaleDrawable.setLevel(10);

        // test clip
        ImageView testClip = (ImageView) findViewById(R.id.test_clip);
        ClipDrawable testClipDrawable = (ClipDrawable) testClip.getDrawable();
        testClipDrawable.setLevel(8000);
        
        // test custom drawable
        View testCustomDrawable = findViewById(R.id.test_custom_drawable);
        CustomDrawable customDrawable = new CustomDrawable(Color.parseColor("#0ac39e"));
        testCustomDrawable.setBackgroundDrawable(customDrawable);
    }
}
 
源代码5 项目: Telegram-FOSS   文件: ActionBarMenuItem.java
public void addSubItem(int id, View view, int width, int height) {
    createPopupLayout();
    view.setLayoutParams(new LinearLayout.LayoutParams(width, height));
    popupLayout.addView(view);
    view.setTag(id);
    view.setOnClickListener(view1 -> {
        if (popupWindow != null && popupWindow.isShowing()) {
            if (processedPopupClick) {
                return;
            }
            processedPopupClick = true;
            popupWindow.dismiss(allowCloseAnimation);
        }
        if (parentMenu != null) {
            parentMenu.onItemClick((Integer) view1.getTag());
        } else if (delegate != null) {
            delegate.onItemClick((Integer) view1.getTag());
        }
    });
    view.setBackgroundDrawable(Theme.getSelectorDrawable(false));
}
 
源代码6 项目: Android-utils   文件: ViewUtils.java
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void setBackground(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
}
 
源代码7 项目: V.FlyoutTest   文件: FragmentArgumentsSupport.java
/**
 * Create the view for this fragment, using the arguments given to it.
 */
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.hello_world, container, false);
    View tv = v.findViewById(R.id.text);
    ((TextView)tv).setText(mLabel != null ? mLabel : "(no label)");
    tv.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.gallery_thumb));
    return v;
}
 
源代码8 项目: guanggoo-android   文件: MenuItemBadge.java
public static void setBackgroundCompat(View v, Drawable d) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        v.setBackgroundDrawable(d);
    } else {
        v.setBackground(d);
    }
}
 
源代码9 项目: DialogSheet   文件: DialogSheet.java
public DialogSheet setRoundedCorners(boolean roundedCorners) {
    if (!roundedCorners) {
        View bgView = bottomSheetDialog.findViewById(R.id.mainDialogContainer);
        if (bgView != null)
            bgView.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.dialog_sheet_main_background));
    }

    return this;
}
 
源代码10 项目: injor   文件: BackroundProcessor.java
@Override
public void process(final View view, String resName, ResourceManager resourceManager, boolean isInUiThread) {
	final Drawable drawable = resourceManager.getDrawable(resName);
	if (drawable != null) {
		if (isInUiThread) {
			view.setBackgroundDrawable(drawable);
		} else {
			UITaskManager.getInstance().post(new Runnable() {
				@Override
				public void run() {
					view.setBackgroundDrawable(drawable);
				}
			});
		}
	} else {
		try {
			final int color = resourceManager.getColor(resName);
			if (isInUiThread) {
				view.setBackgroundColor(color);
			} else {
				UITaskManager.getInstance().post(new Runnable() {
					@Override
					public void run() {
						view.setBackgroundColor(color);
					}
				});
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
源代码11 项目: Mover   文件: ViewUtils.java
/**
 * Sets background, independence of API Level
 *
 * @param view target
 * @param drawable background
 */
public static void setBackground(View view, Drawable drawable){
    if(Build.VERSION.SDK_INT > 16) {
        view.setBackground(drawable);
    }else{
        view.setBackgroundDrawable(drawable);
    }
}
 
源代码12 项目: Silence   文件: ViewUtil.java
@SuppressWarnings("deprecation")
public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
  if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
    v.setBackground(drawable);
  } else {
    v.setBackgroundDrawable(drawable);
  }
}
 
源代码13 项目: pixate-freestyle-android   文件: PXDrawableUtil.java
/**
 * Sets a background {@link Drawable} on a view.
 * 
 * @param view
 * @param drawable
 */
@SuppressWarnings("deprecation")
public static void setBackgroundDrawable(View view, Drawable drawable) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setBackgroundJB(view, drawable);
    } else {
        view.setBackgroundDrawable(drawable);
    }
}
 
源代码14 项目: WelikeAndroid   文件: AsyncBitmapLoader.java
/**
    * 将图片设置到View上
    *
    * @param bitmap
    * @param view
    */
   @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @SuppressWarnings("deprecation")
private void setImageToView(final Bitmap bitmap, final View view) {
       if (view != null) {
           if (view instanceof ImageView) {
               ((ImageView) view).setImageBitmap(bitmap);
           } else {
               if (Build.VERSION.SDK_INT > 15) {
                   view.setBackground(new BitmapDrawable(view.getResources(), bitmap));
               } else {
                   view.setBackgroundDrawable(new BitmapDrawable(view.getResources(), bitmap));
               }
           }
       }
   }
 
源代码15 项目: Social   文件: ViewCompat.java
public static void setBackground(View view, Drawable background) {
	if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
		SDK16.setBackground(view, background);
	} else {
		view.setBackgroundDrawable(background);
	}
}
 
源代码16 项目: NewXmPluginSDK   文件: SettingsItemView.java
public SettingsItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        LayoutInflater inflater = LayoutInflater.from(context);

        View itemView = inflater.inflate(R.layout.settings_item, null);
        mContainerView = itemView;
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        addView(itemView, lp);
        itemView.setBackgroundDrawable(getBackground());
        mTitleTextView = (TextView) itemView.findViewById(R.id.settings_item_title);
        mSubTitleTextView = (TextView) itemView.findViewById(R.id.settings_item_sub_title);
        mSwitchButton = (SwitchButton) itemView.findViewById(R.id.settings_item_switch_btn);
        mOnclickImageView = (ImageView) itemView.findViewById(R.id.settings_item_arrow);
        mInfoTextView = (TextView) itemView.findViewById(R.id.settings_item_info);
        mSelectImageView = (ImageView) itemView.findViewById(R.id.settings_item_select);
        mTitleContainer = itemView.findViewById(R.id.title_container);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SettingsItem, 0, 0);
        String title = a.getString(R.styleable.SettingsItem_item_title);
        String subTitle = a.getString(R.styleable.SettingsItem_item_subtitle);
        String info = a.getString(R.styleable.SettingsItem_item_info);
        mType = a.getInt(R.styleable.SettingsItem_item_type, 1);
        mSelected = a.getBoolean(R.styleable.SettingsItem_item_select, false);
        int lineMargin = a.getDimensionPixelSize(R.styleable.SettingsItem_item_line_margin, 0);
        a.recycle();

        setTitle(title);
        setSubTitle(subTitle);
        setInfo(info);
        setType(mType);

        View view = new View(getContext());
        view.setBackgroundColor(0xffe5e5e5);
        lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 1);
        lp.gravity = Gravity.BOTTOM;
//        int marging = getResources().getDimensionPixelOffset(R.dimen.settings_item_margin);
        lp.setMargins(lineMargin, 0, lineMargin, 0);
        addView(view, lp);
    }
 
源代码17 项目: Genius-Android   文件: UiCompat.java
/**
 * android.support.v4.view.ViewCompat SHOULD include this once and for all!!
 * But it doesn't...
 *
 * @param view       View
 * @param background DrawableBackground
 */
@SuppressWarnings("deprecation")
public static void setBackground(View view, Drawable background) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        UiCompatNotCrash.setBackground(view, background);
    } else {
        view.setBackgroundDrawable(background);
    }
}
 
源代码18 项目: Abelana-Android   文件: PickerFragment.java
private void inflateTitleBar(ViewGroup view) {
    ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_picker_title_bar_stub);
    if (stub != null) {
        View titleBar = stub.inflate();

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);
        listView.setLayoutParams(layoutParams);

        if (titleBarBackground != null) {
            titleBar.setBackgroundDrawable(titleBarBackground);
        }

        doneButton = (Button) view.findViewById(R.id.com_facebook_picker_done_button);
        if (doneButton != null) {
            doneButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    logAppEvents(true);
                    appEventsLogged = true;

                    if (onDoneButtonClickedListener != null) {
                        onDoneButtonClickedListener.onDoneButtonClicked(PickerFragment.this);
                    }
                }
            });

            if (getDoneButtonText() != null) {
                doneButton.setText(getDoneButtonText());
            }

            if (doneButtonBackground != null) {
                doneButton.setBackgroundDrawable(doneButtonBackground);
            }
        }

        titleTextView = (TextView) view.findViewById(R.id.com_facebook_picker_title);
        if (titleTextView != null) {
            if (getTitleText() != null) {
                titleTextView.setText(getTitleText());
            }
        }
    }
}
 
源代码19 项目: FireFiles   文件: Utils.java
public static void tintWidget(View view, int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(view.getBackground());
    DrawableCompat.setTint(wrappedDrawable.mutate(), color);
    view.setBackgroundDrawable(wrappedDrawable);
}
 
源代码20 项目: MaterialQQLite   文件: ColorChooserDialog.java
private void setBackgroundCompat(View view, Drawable d) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
        view.setBackground(d);
    else view.setBackgroundDrawable(d);
}
 
 方法所在类
 同类方法