本文整理匯總了Java中android.content.res.Resources.getDrawable方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getDrawable方法的具體用法?Java Resources.getDrawable怎麽用?Java Resources.getDrawable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.getDrawable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onBindViewHolder
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
HeaderItem headerItem = ((ListRow) item).getHeaderItem();
View view = viewHolder.view;
ImageView headerIcon = (ImageView) view.findViewById(R.id.header_icon);
TextView headerLabel = (TextView) view.findViewById(R.id.header_label);
Resources resources = view.getContext().getResources();
String streamingPrefix = resources.getString(R.string.streaming_prefix);
if (headerItem.getName().startsWith(streamingPrefix)) {
Drawable camIcon = resources.getDrawable(R.drawable.ic_videocam_white_24dp);
headerIcon.setImageDrawable(camIcon);
((ListRow) item).setHeaderItem(new HeaderItem(headerItem.getName()
.substring(streamingPrefix.length())));
} else {
Drawable movieIcon = resources.getDrawable(R.drawable.ic_local_movies_white_24dp);
headerIcon.setImageDrawable(movieIcon);
headerLabel.setText(headerItem.getName());
}
}
示例2: startImg
import android.content.res.Resources; //導入方法依賴的package包/類
private void startImg(Editable text, Attributes attributes, HtmlCompat.ImageGetter img) {
String src = attributes.getValue("", "src");
Drawable d = null;
if (img != null) {
d = img.getDrawable(src, attributes);
}
if (d == null) {
Resources res = mContext.getResources();
d = res.getDrawable(R.drawable.unknown_image);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
}
int len = text.length();
text.append("\uFFFC");
text.setSpan(new ImageSpan(d, src), len, text.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
示例3: getCategoryIcon
import android.content.res.Resources; //導入方法依賴的package包/類
public Drawable getCategoryIcon(final Category category) {
final Resources resources = itemView.getResources();
switch (category) {
case ACCOMMODATION:
return resources.getDrawable(R.drawable.ic_hotel_black);
case FOOD:
return resources.getDrawable(R.drawable.ic_food_black);
case TRANSPORT:
return resources.getDrawable(R.drawable.ic_transport_black);
case ENTERTAINMENT:
return resources.getDrawable(R.drawable.ic_entertainment_black);
case BUSINESS:
return resources.getDrawable(R.drawable.ic_business_black);
case OTHER:
default:
return resources.getDrawable(R.drawable.ic_other_black);
}
}
示例4: init
import android.content.res.Resources; //導入方法依賴的package包/類
public void init(Context context) {
final Resources res = context.getResources();
res1 = R.mipmap.ic_launcher;
res2 = R.mipmap.ic_launcher_round;
drawable1 = res.getDrawable(res1);
drawable2 = res.getDrawable(res2);
bitmap1 = BitmapFactory.decodeResource(res, res1);
bitmap2 = BitmapFactory.decodeResource(res, res2);
color1 = Color.RED;
color2 = Color.GREEN;
textColorRes1 = android.R.color.holo_red_light;
textColorRes2 = android.R.color.black;
textSizeRes1 = R.dimen.dip_20;
textSizeRes2 = R.dimen.dip_30;
textRes1 = R.string.text_1;
textRes2 = R.string.text_3;
int size = res.getDimensionPixelSize(textSizeRes2);
}
示例5: resolveResource
import android.content.res.Resources; //導入方法依賴的package包/類
private Drawable resolveResource()
{
Resources rsrc = getResources();
if (rsrc == null)
{
return null;
}
Drawable d = null;
if (mResource != 0)
{
try
{
d = rsrc.getDrawable(mResource);
}
catch (Exception e)
{
Log.w(TAG, "Unable to find resource: " + mResource, e);
// Don't try again.
mResource = 0;
}
}
return RoundedDrawable.fromDrawable(d);
}
示例6: getResBitmap
import android.content.res.Resources; //導入方法依賴的package包/類
private Bitmap getResBitmap(int bmpResId) {
Options opts = new Options();
opts.inDither = false;
Resources res = getResources();
Bitmap bmp = BitmapFactory.decodeResource(res, bmpResId, opts);
if (bmp == null && isInEditMode()) {
// BitmapFactory.decodeResource doesn't work from the rendering
// library in Eclipse's Graphical Layout Editor. Use this workaround instead.
Drawable d = res.getDrawable(bmpResId);
int w = d.getIntrinsicWidth();
int h = d.getIntrinsicHeight();
bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
Canvas c = new Canvas(bmp);
d.setBounds(0, 0, w - 1, h - 1);
d.draw(c);
}
return bmp;
}
示例7: dynamicDrawables
import android.content.res.Resources; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private void dynamicDrawables(CompositionAvatarView view) {
Resources resources = getResources();
Drawable[] drawables = {
resources.getDrawable(R.drawable.image_1),
resources.getDrawable(R.drawable.image_2),
resources.getDrawable(R.drawable.image_3),
resources.getDrawable(R.drawable.image_4),
resources.getDrawable(R.drawable.image_5)
};
view.addDrawable(drawables[0]);
mDynamicDrawablesRunnable = new Runnable() {
boolean reverse = false;
@Override
public void run() {
if (!reverse) {
view.addDrawable(drawables[view.getNumberOfDrawables()]);
if (view.getNumberOfDrawables() == drawables.length)
reverse = true;
} else {
view.removeDrawableAt(view.getNumberOfDrawables() - 1);
if (view.getNumberOfDrawables() == 1)
reverse = false;
}
mHandler.postDelayed(this, 1500);
}
};
}
示例8: setPlayIconAndDisableControls
import android.content.res.Resources; //導入方法依賴的package包/類
private void setPlayIconAndDisableControls(boolean disable) {
Resources res = getResources();
Drawable play = res.getDrawable(R.drawable.ic_play);
mPlay.setImageDrawable(play);
if(disable) {
setControlsEnabled(false);
}
}
示例9: TransformedImageDrawable
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* @param gravity If one of the Gravity center values, the x and y offset will take the width
* and height of the image into account to center the image to the offset.
*/
TransformedImageDrawable(Context context, Resources res, int resourceId, float xPct, float yPct,
int gravity) {
mImage = res.getDrawable(resourceId, context.getTheme());
mXPercent = xPct;
mYPercent = yPct;
mGravity = gravity;
}
示例10: getDrawableFromResourceUri
import android.content.res.Resources; //導入方法依賴的package包/類
Drawable getDrawableFromResourceUri(Uri uri) throws FileNotFoundException {
String authority = uri.getAuthority();
if (TextUtils.isEmpty(authority)) {
throw new FileNotFoundException("No authority: " + uri);
}
try {
Resources r = this.mContext.getPackageManager().getResourcesForApplication(authority);
List<String> path = uri.getPathSegments();
if (path == null) {
throw new FileNotFoundException("No path: " + uri);
}
int id;
int len = path.size();
if (len == 1) {
try {
id = Integer.parseInt((String) path.get(0));
} catch (NumberFormatException e) {
throw new FileNotFoundException("Single path segment is not a resource ID: " + uri);
}
} else if (len == 2) {
id = r.getIdentifier((String) path.get(1), (String) path.get(0), authority);
} else {
throw new FileNotFoundException("More than two path segments: " + uri);
}
if (id != 0) {
return r.getDrawable(id);
}
throw new FileNotFoundException("No resource found for: " + uri);
} catch (NameNotFoundException e2) {
throw new FileNotFoundException("No package found for authority: " + uri);
}
}
示例11: LatinKeyboard
import android.content.res.Resources; //導入方法依賴的package包/類
public LatinKeyboard(Context context, int xmlLayoutResId, int mode) {
super(context, xmlLayoutResId, mode);
final Resources res = context.getResources();
mContext = context;
mMode = mode;
mRes = res;
mShiftLockIcon = res.getDrawable(R.drawable.sym_keyboard_shift_locked);
mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked);
setDefaultBounds(mShiftLockPreviewIcon);
mSpaceIcon = res.getDrawable(R.drawable.sym_keyboard_space);
mSpaceAutoCompletionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led);
mSpacePreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_space);
mMicIcon = res.getDrawable(R.drawable.sym_keyboard_mic);
mMicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_mic);
setDefaultBounds(mMicPreviewIcon);
mButtonArrowLeftIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_left);
mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right);
m123MicIcon = res.getDrawable(R.drawable.sym_keyboard_123_mic);
m123MicPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_123_mic);
mHintIcon = res.getDrawable(R.drawable.hint_popup);
setDefaultBounds(m123MicPreviewIcon);
sSpacebarVerticalCorrection = res.getDimensionPixelOffset(
R.dimen.spacebar_vertical_correction);
mIsAlphaKeyboard = xmlLayoutResId == R.xml.kbd_qwerty
|| xmlLayoutResId == R.xml.kbd_qwerty_black;
// The index of space key is available only after Keyboard constructor has finished.
mSpaceKeyIndexArray = new int[] { indexOf(KP2AKeyboard.KEYCODE_SPACE) };
initializeNumberHintResources(context);
// TODO remove this initialization after cleanup
mVerticalGap = super.getVerticalGap();
}
示例12: getDrawableForDensity
import android.content.res.Resources; //導入方法依賴的package包/類
@Nullable
public static Drawable getDrawableForDensity(@NonNull Resources res, @DrawableRes int id, int density, @Nullable Theme theme) throws NotFoundException {
if (VERSION.SDK_INT >= 21) {
return ResourcesCompatApi21.getDrawableForDensity(res, id, density, theme);
}
if (VERSION.SDK_INT >= 15) {
return ResourcesCompatIcsMr1.getDrawableForDensity(res, id, density);
}
return res.getDrawable(id);
}
示例13: CandidateView
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Construct a CandidateView for showing suggested words for completion.
* @param context
* @param attrs
*/
public CandidateView(Context context, AttributeSet attrs) {
super(context, attrs);
mSelectionHighlight = context.getResources().getDrawable(
R.drawable.list_selector_background_pressed);
LayoutInflater inflate =
(LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Resources res = context.getResources();
mPreviewPopup = new PopupWindow(context);
mPreviewText = (TextView) inflate.inflate(R.layout.candidate_preview, null);
mPreviewPopup.setWindowLayoutMode(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
mPreviewPopup.setContentView(mPreviewText);
mPreviewPopup.setBackgroundDrawable(null);
mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation);
mColorNormal = res.getColor(R.color.candidate_normal);
mColorRecommended = res.getColor(R.color.candidate_recommended);
mColorOther = res.getColor(R.color.candidate_other);
mDivider = res.getDrawable(R.drawable.keyboard_suggest_strip_divider);
mAddToDictionaryHint = res.getString(R.string.hint_add_to_dictionary);
mPaint = new Paint();
mPaint.setColor(mColorNormal);
mPaint.setAntiAlias(true);
mPaint.setTextSize(mPreviewText.getTextSize());
mPaint.setStrokeWidth(0);
mPaint.setTextAlign(Align.CENTER);
mDescent = (int) mPaint.descent();
mMinTouchableWidth = (int)res.getDimension(R.dimen.candidate_min_touchable_width);
mGestureDetector = new GestureDetector(
new CandidateStripGestureListener(mMinTouchableWidth));
setWillNotDraw(false);
setHorizontalScrollBarEnabled(false);
setVerticalScrollBarEnabled(false);
scrollTo(0, getScrollY());
}
示例14: setDrawable
import android.content.res.Resources; //導入方法依賴的package包/類
public void setDrawable(Resources res, int resId) {
// Note we explicitly don't set mResourceId to resId since we allow the drawable to be
// swapped at runtime and want to re-use the existing resource id for identification.
Drawable drawable = resId == 0 ? null : res.getDrawable(resId);
// Mutate the drawable so we can animate shared drawable properties.
mDrawable = drawable != null ? drawable.mutate() : null;
resizeDrawables();
setState(STATE_INACTIVE);
}
示例15: getImageOnLoading
import android.content.res.Resources; //導入方法依賴的package包/類
public Drawable getImageOnLoading(Resources res) {
return imageResOnLoading != 0 ? res.getDrawable(imageResOnLoading) : imageOnLoading;
}