當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageView.setBackground方法代碼示例

本文整理匯總了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;
}
 
開發者ID:smartbeng,項目名稱:PaoMovie,代碼行數:22,代碼來源:GifViewUtils.java

示例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);
    }
}
 
開發者ID:ifadai,項目名稱:SuperNote,代碼行數:24,代碼來源:RvNoteFolderAdapter.java

示例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());
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:23,代碼來源:ColorPickerPreference.java

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

        }
    }
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:14,代碼來源:ThemePreference.java

示例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;
}
 
開發者ID:anmingyu11,項目名稱:SwipeBackController,代碼行數:16,代碼來源:SwipeBackController.java

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

}
 
開發者ID:mervinderuiter,項目名稱:home-assistant-android,代碼行數:40,代碼來源:Surface.java

示例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);
    }
}
 
開發者ID:funnyzhaov,項目名稱:Tribe,代碼行數:14,代碼來源:CountryDetailActivity.java

示例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);
    }
}
 
開發者ID:fengdongfei,項目名稱:CXJPadProject,代碼行數:10,代碼來源:VersionUtils.java

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

}
 
開發者ID:googlecodelabs,項目名稱:style-transfer,代碼行數:12,代碼來源:MainActivity.java

示例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;
}
 
開發者ID:Samsung,項目名稱:microbit,代碼行數:34,代碼來源:PairingActivity.java

示例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);
}
 
開發者ID:EggUncle,項目名稱:XposedNavigationBar,代碼行數:37,代碼來源:BtnFuncFactory.java

示例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);
        }
    }
 
開發者ID:mervinderuiter,項目名稱:home-assistant-android,代碼行數:43,代碼來源:Surface.java

示例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);
            }
        }
    }
 
開發者ID:mervinderuiter,項目名稱:home-assistant-android,代碼行數:62,代碼來源:Surface.java

示例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();
        }
    }
}
 
開發者ID:stefanonicolai,項目名稱:AstronomyTourPadova,代碼行數:57,代碼來源:ShowCategoriesActivity.java

示例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();
}
 
開發者ID:stefanonicolai,項目名稱:AstronomyTourPadova,代碼行數:80,代碼來源:ShowCategoriesActivity.java


注:本文中的android.widget.ImageView.setBackground方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。