本文整理汇总了Java中android.widget.ImageView.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java ImageView.setBackground方法的具体用法?Java ImageView.setBackground怎么用?Java ImageView.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ImageView
的用法示例。
在下文中一共展示了ImageView.setBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setResource
import android.widget.ImageView; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@SuppressWarnings("deprecation")
static boolean setResource(ImageView view, boolean isSrc, int resId) {
Resources res = view.getResources();
if (res != null) {
try {
GifDrawable d = new GifDrawable(res, resId);
if (isSrc) {
view.setImageDrawable(d);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(d);
} else {
view.setBackgroundDrawable(d);
}
return true;
} catch (Exception ignored) {
// ignored
}
}
return false;
}
示例2: convert
import android.widget.ImageView; //导入方法依赖的package包/类
@Override
protected void convert(BaseViewHolder helper, NoteFolder item) {
helper.setText(R.id.tv_folder_list_title, item.getFolderName())
.setText(R.id.tv_folder_list_count, item.getNoteCount() + "");
RelativeLayout rlItem=helper.getView(R.id.rl_folder_root);
TextView tvTitle=helper.getView(R.id.tv_folder_list_title);
TextView tvCount=helper.getView(R.id.tv_folder_list_count);
ImageView ivIcon=helper.getView(R.id.iv_folder_list_ic);
if(Constans.currentFolder == helper.getLayoutPosition()-getHeaderLayoutCount()){
rlItem.setSelected(true);
tvTitle.setTextColor(ThemeUtils.getColorPrimary(mContext));
tvCount.setTextColor(ThemeUtils.getColorPrimary(mContext));
ivIcon.setBackground(MyDrawable.getIcFolderSelectedDrawable( ThemeUtils.getColorPrimary(mContext)));
} else {
rlItem.setSelected(false);
tvTitle.setTextColor(MainApplication.getContext().getResources().getColor(R.color.colorBlackAlpha87));
tvCount.setTextColor(MainApplication.getContext().getResources().getColor(R.color.colorBlackAlpha54));
ivIcon.setBackgroundResource(R.drawable.ic_folder_un_selected);
}
}
示例3: setPreviewColor
import android.widget.ImageView; //导入方法依赖的package包/类
private void setPreviewColor() {
if (mView == null) return;
ImageView iView = new ImageView(getContext());
LinearLayout widgetFrameView = ((LinearLayout)mView.findViewById(android.R.id.widget_frame));
if (widgetFrameView == null) return;
widgetFrameView.setVisibility(View.VISIBLE);
widgetFrameView.setPadding(
widgetFrameView.getPaddingLeft(),
widgetFrameView.getPaddingTop(),
(int)(mDensity * 8),
widgetFrameView.getPaddingBottom()
);
// remove already create preview image
int count = widgetFrameView.getChildCount();
if (count > 0) {
widgetFrameView.removeViews(0, count);
}
widgetFrameView.addView(iView);
widgetFrameView.setMinimumWidth(0);
iView.setBackground(new AlphaPatternDrawable((int)(5 * mDensity)));
iView.setImageBitmap(getPreviewBitmap());
}
示例4: createCircularPreferenceBitmap
import android.widget.ImageView; //导入方法依赖的package包/类
public static void createCircularPreferenceBitmap(Boolean isImage, Preference preference, ImageView imageView, Context context, int color) {
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
int dimen = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
Bitmap bmp = Bitmap.createBitmap(dimen, dimen, conf);
if (isImage) {
imageView.setBackground(createRoundedBitmapDrawable(bmp, color, context.getResources()));
} else {
preference.setIcon(createRoundedBitmapDrawable(bmp, color, context.getResources()));
}
}
示例5: setDecorBackgroundDrawable
import android.widget.ImageView; //导入方法依赖的package包/类
/**
* 设置窗口根布局的背景图片,这张图将以子view的模式加到decorView中
* <p/>
* Sets the background image of the decorView, this drawable will be a child ImageView of decorView.
*
* @param decorBackgroundDrawable
*/
public SwipeBackController setDecorBackgroundDrawable(Drawable decorBackgroundDrawable) {
mDecorBackgroundDrawable = decorBackgroundDrawable;
final ImageView bgImageView = new ImageView(mActivity);
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
decorView.addView(bgImageView, 0, params);
bgImageView.setBackground(mDecorBackgroundDrawable);
return this;
}
示例6: setHassEntities
import android.widget.ImageView; //导入方法依赖的package包/类
private void setHassEntities() {
HassGroupEntity group = hassEntities.searchGroupEntity(hassGroup);
if (group != null) {
for (HassEntity entity : group.getEntities()) {
View shortcutButton = getLayoutInflater().inflate(R.layout.shortcut_button, null);
Drawable drawable = thisActivity.getDrawable(getHassIconResource(entity.getIcon()));
drawable.setTint(getResources().getColor(R.color.white));
ImageView childImage = (ImageView)shortcutButton.findViewById(R.id.buttonImage);
childImage.setBackground(drawable);
shortcutButtons.addView(shortcutButton);
if (entity instanceof HassGroupEntity) {
setHassButtonGroup((HassGroupEntity) entity, shortcutButton);
}
if (entity instanceof HassClimateEntity) {
final View climateContainer = getLayoutInflater().inflate(R.layout.climate_big, null);
scrollViewItems.addView(climateContainer);
setClimateView(climateContainer, (ClimateControlInterface) entity);
shortcutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollView.smoothScrollTo(climateContainer.getLeft(), 0);
}
});
}
}
} else {
showSettings();
setupError.setText("Group not found");
}
}
示例7: initLikeListener
import android.widget.ImageView; //导入方法依赖的package包/类
/**
* 初始化喜欢布局事件
*/
private void initLikeListener(){
mLikell=(LinearLayout)findViewById(R.id.like_ll);
mLikell.setOnClickListener(this);
mLikeIv=(ImageView)findViewById(R.id.like_iv);
if (mCountry.getGuan()==0){
mLikeIv.setBackground(mDraLikeNo);
}else {
mLikeIv.setBackground(mDraLikePressed);
}
}
示例8: setBackground
import android.widget.ImageView; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void setBackground(Drawable imagebakground,ImageView view){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
view.setBackground(imagebakground);
} else {
view.setBackgroundDrawable(imagebakground);
}
}
示例9: getView
import android.widget.ImageView; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.images, null);
}
image = (ImageView) convertView.findViewById(R.id.imagex);
image.setBackground(items.get(position));
return convertView;
}
示例10: toggleLED
import android.widget.ImageView; //导入方法依赖的package包/类
/**
* Sets a clicked cell on/off.
*
* @param image An image of a clicked cell.
* @param pos Position of a clicked cell.
* @return True, if cell is on and false otherwise.
*/
private boolean toggleLED(ImageView image, int pos) {
boolean isOn;
//Toast.makeText(this, "Pos :" + pos, Toast.LENGTH_SHORT).show();
int state = (Integer) image.getTag(R.id.ledState);
if(state != 1) {
DEVICE_CODE_ARRAY[pos] = 1;
image.setBackground(getApplication().getResources().getDrawable(R.drawable.red_white_led_btn));
image.setTag(R.id.ledState, 1);
isOn = true;
} else {
DEVICE_CODE_ARRAY[pos] = 0;
image.setBackground(getApplication().getResources().getDrawable(R.drawable.white_red_led_btn));
image.setTag(R.id.ledState, 0);
isOn = false;
// Update the code to consider the still ON LED below the toggled one
if(pos < 20) {
DEVICE_CODE_ARRAY[pos + 5] = 1;
}
}
image.setSelected(false);
int position = (Integer) image.getTag(R.id.position);
image.setContentDescription("" + position + getLEDStatus(pos));
return isOn;
}
示例11: createBtnAndSetFunc
import android.widget.ImageView; //导入方法依赖的package包/类
/**
* 创建按钮并且设置对应功能
*
* @param line
* @param sc
*/
public void createBtnAndSetFunc(LinearLayout line, ShortCut sc) {
int iconScale = DataHook.iconScale;
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
p.weight = 1;
p.gravity = Gravity.CENTER;
Context context = line.getContext();
ImageView btn = new ImageView(context);
String iconPath = sc.getIconPath();
Bitmap iconBitmap = null;
if (iconPath != null) {
iconBitmap = ImageUtil.zoomBitmap(iconPath, iconScale);
}
if (iconBitmap == null) {
iconBitmap = ImageUtil.byte2Bitmap(mMapImgRes.get(sc.getCode()));
iconBitmap = ImageUtil.zommBitmap(iconBitmap, iconScale);
}
btn.setImageBitmap(iconBitmap);
ColorStateList colorStateList = createColorStateList(0xffffffff, 0xffffff00, 0xff0000ff, 0xffff0000);
RippleDrawable ripple = new RippleDrawable(colorStateList, null, null);
btn.setBackground(ripple);
btn.setScaleType(ImageView.ScaleType.CENTER);
btn.setOnClickListener(getBtnFuncOfName(sc));
btn.setOnLongClickListener(getBtnLongFuncOfName(sc.getCode()));
line.addView(btn, p);
}
示例12: showChildEntityView
import android.widget.ImageView; //导入方法依赖的package包/类
private void showChildEntityView(ArrayList<LightControlInterface> lightControlInterfaces, final View childEntityContainer, View lightControlView, int color) {
childEntityViews.add(childEntityContainer);
childEntityContainer.setVisibility(View.VISIBLE);
LinearLayout childEntityView = (LinearLayout)childEntityContainer.findViewById(R.id.childEntityView);
childEntityView.removeAllViews();
ImageButton closeButton = (ImageButton)childEntityContainer.findViewById(R.id.closeButton);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hideChildEntityView(childEntityContainer);
}
});
childEntityView.removeAllViews();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.CENTER_IN_PARENT,1);
for (LightControlInterface lightControlInterface : lightControlInterfaces) {
View child = getLayoutInflater().inflate(R.layout.lightcontrol_list_item_small, null);
TextView childText = (TextView)child.findViewById(R.id.buttonText);
childText.setText(lightControlInterface.getName());
try {
String icon = lightControlInterface.getIcon();
if (icon.length() > 0 && icon.substring(0, 4).equals("mdi:")) {
ImageView childImage = (ImageView)child.findViewById(R.id.buttonImage);
Drawable iconDrawable = thisActivity.getDrawable(getHassIconResource(lightControlInterface.getIcon()));
iconDrawable.setTint(getResources().getColor(R.color.white));
childImage.setBackground(iconDrawable);
}
} catch (Exception e) {
Log.e("ChildEntityView", e.getMessage());
}
childEntityView.addView(child);
setLightControlButton(lightControlInterface, child, childEntityContainer, lightControlView);
}
}
示例13: setHassButtonGroup
import android.widget.ImageView; //导入方法依赖的package包/类
private void setHassButtonGroup(HassGroupEntity groupEntity, View shortcutButton) {
final View groupContainer = getLayoutInflater().inflate(R.layout.group_list_vertical_scrollable, null);
scrollViewItems.addView(groupContainer);
LinearLayout groupsView = (LinearLayout)groupContainer.findViewById(R.id.groupsView);
View childContainer = getLayoutInflater().inflate(R.layout.childentity_list_vertical_scrollable, null);
scrollViewItems.addView(childContainer);
childContainer.setVisibility(GONE);
View lightControl = getLayoutInflater().inflate(R.layout.lightcontrol, null);
scrollViewItems.addView(lightControl);
lightControl.setVisibility(GONE);
shortcutButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollView.smoothScrollTo(groupContainer.getLeft(), 0);
}
});
for (HassEntity entity : groupEntity.getEntities()) {
View child = getLayoutInflater().inflate(R.layout.lightcontrol_list_item_medium, null);
LinearLayout buttonLayout = (LinearLayout)child.findViewById(R.id.buttonLayout);
Drawable background = buttonLayout.getBackground();
background.setTint(entity.getColor());
TextView childText = (TextView)child.findViewById(R.id.buttonText);
childText.setText(entity.getName());
try {
String icon = entity.getIcon();
Drawable drawable = thisActivity.getDrawable(getHassIconResource(icon));
drawable.setTint(getResources().getColor(R.color.white));
ImageView childImage = (ImageView)child.findViewById(R.id.buttonImage);
childImage.setBackground(drawable);
} catch (Exception e) {
Log.e("LightControl", e.getMessage());
}
groupsView.addView(child);
if (entity instanceof LightControlInterface) {
setLightControlButton((LightControlInterface)entity, child, childContainer, lightControl);
}
if (entity instanceof SceneInterface) {
setSceneButton((SceneInterface) entity, child);
}
if (entity instanceof SensorInterface) {
setSensor((SensorInterface) entity, child);
}
}
}
示例14: onResume
import android.widget.ImageView; //导入方法依赖的package包/类
@Override
protected void onResume() {
Log.d(TAG, "onResume()");
super.onResume();
atCategories = AtUtils.getAllCategories(getApplicationContext());
Log.d(TAG, "CATEGORIES: " + atCategories.toString());
SharedPreferences sharedpreferences = getSharedPreferences(Utils.AtSharedPreference, MODE_PRIVATE);
// Populating the View
for(Map.Entry<Integer, String> entry : dbCatConverter.entrySet()) {
Integer categoryId = entry.getKey();
String categoryName = entry.getValue();
int rId = getResources().getIdentifier("textViewCategories" + categoryId.toString(), "id", getPackageName());
TextView currCategory = (TextView) findViewById(rId);
currCategory.setText(categoryName);
// Maybe it's a selected one?
Integer categoryIdSelected = sharedpreferences.getInt(Utils.keyCurrentCategoryId, 0); //0 is the default value.
int rVcId = getResources().getIdentifier("imageViewCategories" + categoryId.toString(), "id", getPackageName());
ImageView imageViewCategory = (ImageView) findViewById(rVcId);
if( categoryIdSelected == categoryId ) {
imageViewCategory.setBackground(getResources().getDrawable(R.drawable.layout_selected));
} else {
imageViewCategory.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
}
}
// Constant SnackBar
final Integer pointId = sharedpreferences.getInt(Utils.keyPointId, 0); //0 is the default value.
final String snackText = sharedpreferences.getString(Utils.keyCurrentSnackbar, "");
if (pointId != 0) {
Log.d(TAG, "sharedpreferences keyPointId:" + pointId);
localSnackbar = Utils.showSnackbar(findViewById(android.R.id.content), snackText, getString(R.string.snackbar_goto_point),
new View.OnClickListener() {
@Override
public void onClick(View view) {
localSnackbar.dismiss();
Intent intent = new Intent(ShowCategoriesActivity.this, ShowPointActivity.class);
Bundle dataBundle = new Bundle();
dataBundle.putString("POINT_ID", pointId.toString());
intent.putExtras(dataBundle);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
);
} else {
if(localSnackbar != null) {
localSnackbar.dismiss();
}
}
}
示例15: onClick
import android.widget.ImageView; //导入方法依赖的package包/类
public void onClick(View view) {
SharedPreferences sharedpreferences = getSharedPreferences(Utils.AtSharedPreference, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
ImageView imageViewAll = (ImageView) findViewById(R.id.imageViewCategoriesAll);
ImageView imageViewCategories4 = (ImageView) findViewById(R.id.imageViewCategories4);
ImageView imageViewCategories5 = (ImageView) findViewById(R.id.imageViewCategories5);
ImageView imageViewCategories6 = (ImageView) findViewById(R.id.imageViewCategories6);
ImageView imageViewCategories7 = (ImageView) findViewById(R.id.imageViewCategories7);
// FIXME: Ugly as hell, but hey, time's up :-(
switch (view.getId()) {
case R.id.categoriesAll:
// All Categories
editor.putInt(Utils.keyCurrentCategoryId, 0);
editor.apply();
// Graphic
imageViewAll.setBackground(getResources().getDrawable(R.drawable.layout_selected));
imageViewCategories4.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories5.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories6.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories7.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
break;
case R.id.categories4:
// Cat 4
editor.putInt(Utils.keyCurrentCategoryId, 4);
editor.apply();
// Graphic
imageViewAll.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories4.setBackground(getResources().getDrawable(R.drawable.layout_selected));
imageViewCategories5.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories6.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories7.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
break;
case R.id.categories5:
// Cat 4
editor.putInt(Utils.keyCurrentCategoryId, 5);
editor.apply();
// Graphic
imageViewAll.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories4.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories5.setBackground(getResources().getDrawable(R.drawable.layout_selected));
imageViewCategories6.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories7.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
break;
case R.id.categories6:
// Cat 4
editor.putInt(Utils.keyCurrentCategoryId, 6);
editor.apply();
// Graphic
imageViewAll.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories4.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories5.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories6.setBackground(getResources().getDrawable(R.drawable.layout_selected));
imageViewCategories7.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
break;
case R.id.categories7:
// Cat 4
editor.putInt(Utils.keyCurrentCategoryId, 7);
editor.apply();
// Graphic
imageViewAll.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories4.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories5.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories6.setBackground(getResources().getDrawable(R.drawable.layout_not_selected));
imageViewCategories7.setBackground(getResources().getDrawable(R.drawable.layout_selected));
break;
}
// Send to List
Intent intentList = new Intent(getApplicationContext(), ListPointsActivity.class);
startActivity(intentList);
finish();
}