当前位置: 首页>>代码示例>>Java>>正文


Java ContextCompat.getDrawable方法代码示例

本文整理汇总了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);
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:26,代码来源:IconUtils.java

示例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());
}
 
开发者ID:PSD-Company,项目名称:duo-navigation-drawer,代码行数:20,代码来源:DuoMenuView.java

示例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);
}
 
开发者ID:lutvie72,项目名称:RackMonthPicker,代码行数:12,代码来源:MonthAdapter.java

示例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()});
    }
}
 
开发者ID:zuoweitan,项目名称:Hitalk,代码行数:39,代码来源:XEditText.java

示例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);
}
 
开发者ID:coderwjq,项目名称:ZhaZhaShop,代码行数:13,代码来源:FloatingItemDecoration.java

示例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);
        }
    }
 
开发者ID:medalionk,项目名称:simple-share-android,代码行数:11,代码来源:IconUtils.java

示例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);
}
 
开发者ID:alphater,项目名称:garras,代码行数:38,代码来源:PhotoFragment.java

示例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;
}
 
开发者ID:HoraApps,项目名称:Liz,代码行数:12,代码来源:ThemeHelper.java

示例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");
    }
}
 
开发者ID:ThirtyDegreesRay,项目名称:OpenHub,代码行数:14,代码来源:ViewUtils.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:SupportDividerItemDecoration.java

示例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();
}
 
开发者ID:florent37,项目名称:CameraFragment,代码行数:33,代码来源:RecordButton.java

示例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);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:8,代码来源:ActionBarDrawerToggle.java

示例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);

}
 
开发者ID:PacktPublishing,项目名称:Android-Wear-Projects,代码行数:7,代码来源:HeartBeatView.java

示例14: setHeaderIcon

import android.support.v4.content.ContextCompat; //导入方法依赖的package包/类
public SubMenu setHeaderIcon(int iconRes) {
    super.setHeaderIconInt(ContextCompat.getDrawable(getContext(), iconRes));
    return this;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:5,代码来源:SubMenuBuilder.java

示例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));
}
 
开发者ID:pchmn,项目名称:MaterialChipsInput,代码行数:71,代码来源:ChipsInput.java


注:本文中的android.support.v4.content.ContextCompat.getDrawable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。