本文整理汇总了Java中android.support.v4.content.ContextCompat.getDrawable方法的典型用法代码示例。如果您正苦于以下问题:Java ContextCompat.getDrawable方法的具体用法?Java ContextCompat.getDrawable怎么用?Java ContextCompat.getDrawable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.content.ContextCompat
的用法示例。
在下文中一共展示了ContextCompat.getDrawable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadMimeIcon
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static Drawable loadMimeIcon(
Context context, String mimeType, String authority, String docId, int mode) {
if (Document.MIME_TYPE_DIR.equals(mimeType)) {
if (MediaDocumentsProvider.AUTHORITY.equals(authority)) {
if(docId.startsWith(MediaDocumentsProvider.TYPE_ALBUM)){
return ContextCompat.getDrawable(context, R.drawable.ic_doc_album);
}
else if(docId.startsWith(MediaDocumentsProvider.TYPE_IMAGES_BUCKET)){
return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
}
else if(docId.startsWith(MediaDocumentsProvider.TYPE_VIDEOS_BUCKET)){
return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
}
}
if (mode == DocumentsActivity.State.MODE_GRID) {
return ContextCompat.getDrawable(context, R.drawable.ic_grid_folder);
} else {
return ContextCompat.getDrawable(context, R.drawable.ic_doc_folder);
}
}
return loadMimeIcon(context, mimeType);
}
示例2: handleBackground
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* Handles the background.
*/
private void handleBackground() {
if (mMenuViewHolder.mMenuBackground == null) {
return;
}
if (mBackgroundDrawableId != DEFAULT_DRAWABLE_ATTRIBUTE_VALUE) {
Drawable backgroundDrawable = ContextCompat.getDrawable(getContext(), mBackgroundDrawableId);
if (backgroundDrawable != null) {
mMenuViewHolder.mMenuBackground.setImageDrawable(backgroundDrawable);
return;
}
}
mMenuViewHolder.mMenuBackground.setBackgroundColor(getPrimaryColor());
}
示例3: setMonthBackgroundSelected
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void setMonthBackgroundSelected(int color) {
LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.month_selected);
GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(1);
gradientDrawable.setColor(ContextCompat.getColor(context, color));
layerDrawable.setDrawableByLayerId(1, gradientDrawable);
StateListDrawable states = new StateListDrawable();
states.addState(new int[]{android.R.attr.state_selected}, gradientDrawable);
states.addState(new int[]{}, ContextCompat.getDrawable(context, R.drawable.month_default));
layoutMain.setBackground(states);
}
示例4: init
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void init() {
if (getInputType() == InputType.TYPE_CLASS_NUMBER) { // if inputType="number", it can't insert separator.
setInputType(InputType.TYPE_CLASS_PHONE);
}
mTextWatcher = new MyTextWatcher();
this.addTextChangedListener(mTextWatcher);
mRightMarkerDrawable = getCompoundDrawables()[2];
if (customizeMarkerEnable && mRightMarkerDrawable != null) {
setCompoundDrawables(getCompoundDrawables()[0], getCompoundDrawables()[1],
null, getCompoundDrawables()[3]);
setHasNoSeparator(true);
}
if (mRightMarkerDrawable == null) { // didn't customize Marker
mRightMarkerDrawable = ContextCompat.getDrawable(getContext(), R.mipmap.indicator_input_error);
DrawableCompat.setTint(mRightMarkerDrawable, getCurrentHintTextColor());
if (mRightMarkerDrawable != null) {
mRightMarkerDrawable.setBounds(0, 0, mRightMarkerDrawable.getIntrinsicWidth(),
mRightMarkerDrawable.getIntrinsicHeight());
}
}
setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
hasFocused = hasFocus;
markerFocusChangeLogic();
iOSFocusChangeLogic();
}
});
if (iOSStyleEnable) {
initiOSObjects();
}
if (disableEmoji) {
setFilters(new InputFilter[]{new EmojiExcludeFilter()});
}
}
示例5: FloatingItemDecoration
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* 自定义分割线
*
* @param context
* @param drawableId 分割线图片
*/
public FloatingItemDecoration(Context context, @DrawableRes int drawableId) {
mDivider = ContextCompat.getDrawable(context, drawableId);
this.dividerHeight = mDivider.getIntrinsicHeight();
this.dividerWidth = mDivider.getIntrinsicWidth();
init(context);
}
示例6: loadSchemeIcon
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public static Drawable loadSchemeIcon(Context context, String type) {
if (SERVER.equals(type)) {
return ContextCompat.getDrawable(context, R.drawable.ic_connection_server);
} else if (CLIENT.equals(type)) {
return ContextCompat.getDrawable(context, R.drawable.ic_connection_network);
} else {
return ContextCompat.getDrawable(context, R.drawable.ic_connection_server);
}
}
示例7: setupData
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void setupData(Photos.User user) {
if (null == getActivity()) return;
mColorIcon = ContextCompat.getDrawable(getActivity(), R.mipmap.ic_fiber_manual_record_white_18dp);
mUserTxt.setText(getString(R.string.by_photo, user.name));
setTranslate(mUserTxt, DELAY * 4);
try {
Date createdAt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss-HH:mm", Locale.getDefault()).parse(mPhotos.created_at);
mTitleTxt.setText(getString(R.string.shoot_at, new PrettyTime().format(createdAt)));
} catch (ParseException e) {
Timber.e(e);
}
RequestBuilder<Bitmap> bitmapRequestBuilder = GlideApp.with(getActivity())
.asBitmap()
.load(user.profile_image.large)
.error(R.mipmap.bg_dark_avatar_male_big_normal)
.placeholder(R.mipmap.bg_dark_avatar_male_big_normal)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.fallback(R.mipmap.bg_dark_avatar_male_big_normal);
bitmapRequestBuilder.into(new CircularBitmapImageViewTarget(getActivity(), mUserAvatar));
RxView.clicks(mUserAvatar).compose(this.bindUntilEvent(FragmentEvent.DESTROY_VIEW)).throttleFirst(1, TimeUnit.SECONDS).subscribe(new Consumer<Object>() {
@Override
public void accept(Object o) throws Exception {
if (null != mPhotos && null != mPhotos.user) {
Request request = new Request(UserFragment.class);
request.putExtra(UserFragment.EXTRA_USER_NAME_KEY, mPhotos.user.username);
request.putExtra(UserFragment.EXTRA_NIKE_NAME_KEY, mPhotos.user.name);
startFragment(request);
}
}
});
setTranslate(mUserTxt, DELAY * 4);
setTranslate(mUserTxt, DELAY * 5);
}
示例8: getPlaceHolder
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public Drawable getPlaceHolder(){
switch (baseTheme){
case DARK:
return ContextCompat.getDrawable(context, R.drawable.ic_empty);
case AMOLED:
return ContextCompat.getDrawable(context, R.drawable.ic_empty_amoled);
case LIGHT:
return ContextCompat.getDrawable(context, R.drawable.ic_empty_white);
}
return null;
}
示例9: getBitmapFromResource
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* Get bitmap from resource
*/
public static Bitmap getBitmapFromResource(Context context, int drawableId) {
Drawable drawable = ContextCompat.getDrawable(context, drawableId);
if (drawable instanceof BitmapDrawable) {
return BitmapFactory.decodeResource(context.getResources(), drawableId);
} else if (drawable instanceof VectorDrawable) {
return getBitmapFromResource((VectorDrawable) drawable);
} else {
throw new IllegalArgumentException("unsupported drawable type");
}
}
示例10: SupportDividerItemDecoration
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public SupportDividerItemDecoration(Context context, int orientation, boolean dash) {
if (dash) {
mDivider = ContextCompat.getDrawable(context, R.drawable.shape_common_dash_divide);
} else {
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();
}
setOrientation(orientation);
}
示例11: RecordButton
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public RecordButton(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
takePhotoDrawable = ContextCompat.getDrawable(context, R.drawable.take_photo_button);
startRecordDrawable = ContextCompat.getDrawable(context, R.drawable.start_video_record_button);
stopRecordDrawable = ContextCompat.getDrawable(context, R.drawable.stop_button_background);
if (Build.VERSION.SDK_INT > 15)
setBackground(ContextCompat.getDrawable(context, R.drawable.circle_frame_background));
else
setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.circle_frame_background));
setOnClickListener(new OnClickListener() {
private final static int CLICK_DELAY = 1000;
private long lastClickTime = 0;
@Override
public void onClick(View view) {
if (System.currentTimeMillis() - lastClickTime < CLICK_DELAY) {
return;
} else lastClickTime = System.currentTimeMillis();
if(listener != null) {
listener.onRecordButtonClicked();
}
}
});
setSoundEffectsEnabled(false);
setIconPadding(iconPadding);
displayPhotoState();
}
示例12: setHomeAsUpIndicator
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public void setHomeAsUpIndicator(int resId) {
Drawable indicator = null;
if (resId != 0) {
indicator = ContextCompat.getDrawable(this.mActivity, resId);
}
setHomeAsUpIndicator(indicator);
}
示例13: init
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
private void init() {
//make this not mandatory
heartDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_heart_red_24dp);
setImageDrawable(heartDrawable);
}
示例14: setHeaderIcon
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public SubMenu setHeaderIcon(int iconRes) {
super.setHeaderIconInt(ContextCompat.getDrawable(getContext(), iconRes));
return this;
}
示例15: init
import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
/**
* Inflate the view according to attributes
*
* @param attrs the attributes
*/
private void init(AttributeSet attrs) {
// inflate layout
View rootView = inflate(getContext(), R.layout.chips_input, this);
// butter knife
ButterKnife.bind(this, rootView);
// attributes
if(attrs != null) {
TypedArray a = mContext.getTheme().obtainStyledAttributes(
attrs,
R.styleable.ChipsInput,
0, 0);
try {
// hint
mHint = a.getString(R.styleable.ChipsInput_hint);
mHintColor = a.getColorStateList(R.styleable.ChipsInput_hintColor);
mTextColor = a.getColorStateList(R.styleable.ChipsInput_textColor);
mMaxRows = a.getInteger(R.styleable.ChipsInput_maxRows, 2);
setMaxHeight(ViewUtil.dpToPx((40 * mMaxRows) + 8));
//setVerticalScrollBarEnabled(true);
// chip label color
mChipLabelColor = a.getColorStateList(R.styleable.ChipsInput_chip_labelColor);
// chip avatar icon
mChipHasAvatarIcon = a.getBoolean(R.styleable.ChipsInput_chip_hasAvatarIcon, true);
// chip delete icon
mChipDeletable = a.getBoolean(R.styleable.ChipsInput_chip_deletable, false);
mChipDeleteIconColor = a.getColorStateList(R.styleable.ChipsInput_chip_deleteIconColor);
int deleteIconId = a.getResourceId(R.styleable.ChipsInput_chip_deleteIcon, NONE);
if(deleteIconId != NONE) mChipDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId);
// chip background color
mChipBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_chip_backgroundColor);
// show chip detailed
mShowChipDetailed = a.getBoolean(R.styleable.ChipsInput_showChipDetailed, true);
// chip detailed text color
mChipDetailedTextColor = a.getColorStateList(R.styleable.ChipsInput_chip_detailed_textColor);
mChipDetailedBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_chip_detailed_backgroundColor);
mChipDetailedDeleteIconColor = a.getColorStateList(R.styleable.ChipsInput_chip_detailed_deleteIconColor);
// filterable list
mFilterableListBackgroundColor = a.getColorStateList(R.styleable.ChipsInput_filterable_list_backgroundColor);
mFilterableListTextColor = a.getColorStateList(R.styleable.ChipsInput_filterable_list_textColor);
}
finally {
a.recycle();
}
}
// adapter
mChipsAdapter = new ChipsAdapter(mContext, this, mRecyclerView);
ChipsLayoutManager chipsLayoutManager = ChipsLayoutManager.newBuilder(mContext)
.setOrientation(ChipsLayoutManager.HORIZONTAL)
.build();
mRecyclerView.setLayoutManager(chipsLayoutManager);
mRecyclerView.setNestedScrollingEnabled(false);
mRecyclerView.setAdapter(mChipsAdapter);
// set window callback
// will hide DetailedOpenView and hide keyboard on touch outside
Activity activity = ActivityUtil.scanForActivity(mContext);
if(activity == null)
throw new ClassCastException("android.view.Context cannot be cast to android.app.Activity");
android.view.Window.Callback mCallBack = (activity).getWindow().getCallback();
activity.getWindow().setCallback(new MyWindowCallback(mCallBack, activity));
}