當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。