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


Java AppCompatResources.getDrawable方法代码示例

本文整理汇总了Java中android.support.v7.content.res.AppCompatResources.getDrawable方法的典型用法代码示例。如果您正苦于以下问题:Java AppCompatResources.getDrawable方法的具体用法?Java AppCompatResources.getDrawable怎么用?Java AppCompatResources.getDrawable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.content.res.AppCompatResources的用法示例。


在下文中一共展示了AppCompatResources.getDrawable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBitmapFromVectorDrawable

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
/**
 * Converts a vector asset to a bitmap as required by {@link CustomTabsIntent.Builder#setCloseButtonIcon(Bitmap)}
 *
 * @param drawableId The drawable ID
 * @return Bitmap equivalent
 */
private Bitmap getBitmapFromVectorDrawable(final @DrawableRes int drawableId) {
    Drawable drawable = AppCompatResources.getDrawable(this, drawableId);
    if (drawable == null) {
        return null;
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        drawable = (DrawableCompat.wrap(drawable)).mutate();
    }

    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
            drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);

    return bitmap;
}
 
开发者ID:saschpe,项目名称:android-customtabs,代码行数:24,代码来源:MainActivity.java

示例2: getView

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	if (convertView == null) {
		convertView = inflater.inflate(R.layout.item_main_menu, parent, false);
		convertView.setOnClickListener(sectionClickListener);
	}

	Section section = getItem(position);
	convertView.setSelected(section == currentSection);

	TextView tv = convertView.findViewById(R.id.section_text);
	SpannableString sectionTitle = new SpannableString(getString(section.getTitleResId()));
	Drawable sectionIcon = AppCompatResources.getDrawable(MainActivity.this, section.getIconResId());
	if (section == currentSection) {
		// Special color for the current section
		sectionTitle.setSpan(new ForegroundColorSpan(currentSectionForegroundColor), 0, sectionTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		// We need to mutate the drawable before applying the ColorFilter, or else all the similar drawable instances will be tinted.
		sectionIcon.mutate().setColorFilter(currentSectionForegroundColor, PorterDuff.Mode.SRC_IN);
	}
	tv.setText(sectionTitle);
	TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(tv, sectionIcon, null, null, null);

	return convertView;
}
 
开发者ID:cbeyls,项目名称:fosdem-companion-android,代码行数:25,代码来源:MainActivity.java

示例3: onBindViewHolder

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(ViewHolder holder, Cursor cursor) {
	Context context = holder.itemView.getContext();
	Event event = DatabaseManager.toEvent(cursor, holder.event);
	holder.event = event;

	holder.title.setText(event.getTitle());
	boolean isBookmarked = DatabaseManager.toBookmarkStatus(cursor);
	Drawable bookmarkDrawable = isBookmarked
			? AppCompatResources.getDrawable(context, R.drawable.ic_bookmark_grey600_24dp)
			: null;
	TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(holder.title, null, null, bookmarkDrawable, null);
	holder.title.setContentDescription(isBookmarked
			? context.getString(R.string.in_bookmarks_content_description, event.getTitle())
			: null
	);
	String personsSummary = event.getPersonsSummary();
	holder.persons.setText(personsSummary);
	holder.persons.setVisibility(TextUtils.isEmpty(personsSummary) ? View.GONE : View.VISIBLE);
	Track track = event.getTrack();
	holder.trackName.setText(track.getName());
	holder.trackName.setTextColor(ContextCompat.getColor(context, track.getType().getColorResId()));
	holder.trackName.setContentDescription(context.getString(R.string.track_content_description, track.getName()));

	bindDetails(holder, event);
}
 
开发者ID:cbeyls,项目名称:fosdem-companion-android,代码行数:27,代码来源:EventsAdapter.java

示例4: applyAttrs

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
private void applyAttrs(final AttributeSet attrs) {

        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ListItemView);

        try {

            mMenuId = a.getResourceId(R.styleable.ListItemView_liv_menu, NULL);
            mMenuItemsRoom = a.getInteger(R.styleable.ListItemView_liv_menuItemsRoom,
                    DEFAULT_MENU_ITEMS_ROOM);
            mMenuActionColor = a.getColor(R.styleable.ListItemView_liv_menuActionColor,
                    Color.TRANSPARENT);
            mMenuOverflowColor = a.getColor(R.styleable.ListItemView_liv_menuOverflowColor,
                    Color.TRANSPARENT);

            mTitle = a.getString(R.styleable.ListItemView_liv_title);
            mSubtitle = a.getString(R.styleable.ListItemView_liv_subtitle);
            mIsMultiline = a.getBoolean(R.styleable.ListItemView_liv_multiline, false);
            mDisplayMode = a.getInt(R.styleable.ListItemView_liv_displayMode, mDisplayMode);

            mPaddingEnd = a.getDimensionPixelSize(R.styleable.ListItemView_liv_paddingEnd,
                    mPaddingEnd);
            mPaddingStart = a.getDimensionPixelSize(R.styleable.ListItemView_liv_paddingStart,
                    mPaddingStart);
            mKeyline = a.getDimensionPixelSize(R.styleable.ListItemView_liv_keyline, mKeyline);
            mForceKeyline = a.getBoolean(R.styleable.ListItemView_liv_forceKeyline, false);

            int iconDrawableResId = a.getResourceId(R.styleable.ListItemView_liv_icon, NULL);
            if (iconDrawableResId != NULL) {
                mIconDrawable = AppCompatResources.getDrawable(getContext(), iconDrawableResId);
            }

            mIconColor = a.getColor(R.styleable.ListItemView_liv_iconColor, Color.TRANSPARENT);
            mCircularIconColor = a.getColor(R.styleable.ListItemView_liv_circularIconColor,
                    Color.TRANSPARENT);

        } finally {
            a.recycle();
        }
    }
 
开发者ID:lurbas,项目名称:ListItemView,代码行数:40,代码来源:ListItemView.java

示例5: getDrawable

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Override
public Drawable getDrawable() {
    if (mDrawable instanceof EmoticonDrawable) {
        return ((EmoticonDrawable) mDrawable).getDrawable();
    }
    if (mDrawable == null) {
        mDrawable = AppCompatResources.getDrawable(context, drawableRes);
        int width = (textSize * mDrawable.getIntrinsicWidth()) / mDrawable.getIntrinsicHeight();
        mDrawable.setBounds(0, 0, width, textSize);
    }
    return mDrawable;
}
 
开发者ID:hoanganhtuan95ptit,项目名称:GifEmoticon,代码行数:14,代码来源:EmoticonSpan.java

示例6: getDrawable

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
@Override
public Drawable getDrawable() {
    if (mDeferredDrawable == null) {
        mDeferredDrawable = AppCompatResources.getDrawable(mContext, mEmoticonIcon);
        mDeferredDrawable.setBounds(0, 0, (int) mEmoticonSize, (int) mEmoticonSize);
    }
    return mDeferredDrawable;
}
 
开发者ID:kevalpatel2106,项目名称:EmoticonGIFKeyboard,代码行数:10,代码来源:EmoticonSpan.java

示例7: init

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs) {
    if ( null == attrs ) {
        return;
    }

    TypedArray attributeArray = context.obtainStyledAttributes( attrs, R.styleable.TintVtDrTextView);
    Drawable[] drawables = new Drawable[4];
    int[] styleableIds = { R.styleable.TintVtDrTextView_vectorLeft, R.styleable.TintVtDrTextView_vectorTop,
            R.styleable.TintVtDrTextView_vectorRight, R.styleable.TintVtDrTextView_vectorBottom} ;

    int colorId = attributeArray.getResourceId(R.styleable.TintVtDrTextView_vectorTint, -1);
    int tintColor = Color.BLACK;
    if ( -1 != colorId ) {
        tintColor = context.getResources().getColor( colorId );
    }


    for ( int i = 0; i < drawables.length ;i++ ) {
        int rscId = attributeArray.getResourceId(styleableIds[i], -1);
        if ( -1 != rscId ){
            drawables[i] = AppCompatResources.getDrawable(context, rscId) ;

            if ( -1 != tintColor ) {
                DrawableCompat.setTint( drawables[i], tintColor);
            }
        }
    }

    // left, top, right, bottom
    setCompoundDrawablesWithIntrinsicBounds(drawables[0], drawables[1], drawables[2], drawables[3]);
    attributeArray.recycle();
}
 
开发者ID:mithrilcoin-io,项目名称:EosCommander,代码行数:33,代码来源:TintVtDrTextView.java

示例8: initIconDrawable

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
private void initIconDrawable(TypedArray attributes) {
    if (!attributes.hasValue(R.styleable.trinity_mirror_like_button_icon_drawable)) {
        throw new IllegalArgumentException("Missing attribute: icon_drawable");
    }
    Drawable drawable;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        drawable = attributes.getDrawable(R.styleable.trinity_mirror_like_button_icon_drawable);
    } else {
        int iconResId = attributes.getResourceId(R.styleable.trinity_mirror_like_button_icon_drawable, 0);
        drawable = AppCompatResources.getDrawable(getContext(), iconResId);
    }

    setIconDrawable(drawable);
}
 
开发者ID:RicardoBelchior,项目名称:TMButton,代码行数:16,代码来源:TMButton.java

示例9: getDrawable

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
public Drawable getDrawable(int index) {
    if (mWrapped.hasValue(index)) {
        final int resourceId = mWrapped.getResourceId(index, 0);
        if (resourceId != 0) {
            return AppCompatResources.getDrawable(mContext, resourceId);
        }
    }
    return mWrapped.getDrawable(index);
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:10,代码来源:TintTypedArray.java

示例10: getDrawableFor

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
public static Drawable getDrawableFor(Context ctx, int type) {
    Drawable drawable = null;
    if (type == TYPE_WRAP_ANCHOR)
        drawable = AppCompatResources.getDrawable(ctx, R.drawable.ic_format_indent);
    if (drawable != null)
        DrawableCompat.setTint(drawable.mutate(),
                ctx.getResources().getColor(R.color.iconColor));
    return drawable;
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:10,代码来源:MessageBuilder.java

示例11: getDrawable

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
@Nullable
public static Drawable getDrawable(Context context, TypedArray original, int index, int tintResId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return original.getDrawable(index);
    }

    int resId = original.getResourceId(index, 0);
    Drawable drawable = AppCompatResources.getDrawable(context, resId);

    if (drawable != null) {
        Drawable wrapped = DrawableCompat.wrap(drawable);

        DrawableCompat.applyTheme(wrapped, context.getTheme());

        TypedArray a = context.obtainStyledAttributes(new int[]{tintResId});

        ColorStateList tintList = a.getColorStateList(0);

        if (tintList != null) {
            DrawableCompat.setTintList(wrapped, tintList);
        }

        drawable = wrapped;

        a.recycle();
    }

    return drawable;
}
 
开发者ID:Gericop,项目名称:DateTimePicker,代码行数:30,代码来源:Utils.java

示例12: getSkinDrawableCompat

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
private Drawable getSkinDrawableCompat(Context context, int resId) {
    if (AppCompatDelegate.isCompatVectorFromResourcesEnabled()) {
        if (!isDefaultSkin) {
            try {
                return SkinCompatDrawableManager.get().getDrawable(context, resId);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return AppCompatResources.getDrawable(context, resId);
    } else {
        return getSkinDrawable(context, resId);
    }
}
 
开发者ID:ximsfei,项目名称:Android-skin-support,代码行数:15,代码来源:SkinCompatResources.java

示例13: getVectorDrawable

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
public static
@Nullable
Drawable getVectorDrawable(Context context, @DrawableRes int resVector) {
    try {
        return AppCompatResources.getDrawable(context, resVector);
    } catch (Exception e) {
        QMUILog.d(TAG, "Error in getVectorDrawable. resVector=" + resVector + ", resName=" + context.getResources().getResourceName(resVector) + e.getMessage());
        return null;
    }
}
 
开发者ID:QMUI,项目名称:QMUI_Android,代码行数:11,代码来源:QMUIDrawableHelper.java

示例14: addLockToSendButton

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
private void addLockToSendButton() {
    floatingBtn.setText(R.string.action_send);
    Drawable lock = AppCompatResources.getDrawable(this, R.drawable.send_private);
    if (lock != null) {
        lock.setBounds(0, 0, lock.getIntrinsicWidth(), lock.getIntrinsicHeight());
        floatingBtn.setCompoundDrawables(null, null, lock, null);
    }
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:9,代码来源:ComposeActivity.java

示例15: getAlbumItemSelectorOverlay

import android.support.v7.content.res.AppCompatResources; //导入方法依赖的package包/类
public static Drawable getAlbumItemSelectorOverlay(Context context) {
    Drawable selectorOverlay = AppCompatResources.getDrawable(context,
            R.drawable.album_item_selected_indicator);

    if (selectorOverlay == null) {
        return null;
    }
    return tintDrawableWithAccentColor(context, selectorOverlay);
}
 
开发者ID:kollerlukas,项目名称:Camera-Roll-Android-App,代码行数:10,代码来源:Util.java


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