Java Code Examples for android.widget.ImageView.setBackgroundResource()

The following are Jave code examples for showing how to use setBackgroundResource() of the android.widget.ImageView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: SuperNote   File: RvNoteFolderAdapter.java   Source Code and License Vote up 7 votes
@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);
    }
}
 
Example 2
Project: Huochexing12306   File: StationDetailAty.java   Source Code and License Vote up 7 votes
public void loadViews() {
	titles = new String[mMapBitmaps.size()];
	mPics = new ArrayList<ImageView>();
	mDots = new ArrayList<View>();
	int i=0;
	for(String key:mMapBitmaps.keySet()){
		titles[i++] = key;
		ImageView iv1 = new ImageView(StationDetailAty.this);
		iv1.setImageBitmap(mMapBitmaps.get(key));
		iv1.setScaleType(ScaleType.CENTER_CROP);
		iv1.setOnClickListener(new MyOnClickListener(i));
		mPics.add(iv1);
		
		ImageView iv2 = new ImageView(StationDetailAty.this);
		iv2.setBackgroundResource(R.drawable.dot_normal);
		mDots.add(iv2);
	}
	tvTitle.setText(titles[0]);
}
 
Example 3
Project: NanoIconPackLite   File: LiteIconActivity.java   Source Code and License Vote up 7 votes
private View initIconView() {
    FrameLayout contentView = new FrameLayout(LiteIconActivity.this);
    int gridW = (int) (displayMetrics.density * GRID_W_IN_DP);
    int gridH = (int) (displayMetrics.density * GRID_H_IN_DP);
    ViewGroup.LayoutParams lpCv = new ViewGroup.LayoutParams(gridW, gridH);
    contentView.setLayoutParams(lpCv);

    ImageView ivIcon = new ImageView(LiteIconActivity.this);
    ivIcon.setTag("iv");
    ivIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    ivIcon.setClickable(true);
    ivIcon.setBackgroundResource(getClickBg());
    int iconSize = (int) (displayMetrics.density * ICON_SIZE_IN_DP);
    FrameLayout.LayoutParams lpIv = new FrameLayout.LayoutParams(iconSize, iconSize);
    lpIv.gravity = Gravity.CENTER;
    ivIcon.setLayoutParams(lpIv);
    contentView.addView(ivIcon);

    return contentView;
}
 
Example 4
Project: Logistics-guard   File: TestActivity3.java   Source Code and License Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setTitle(title);
    infoText = (TextView) findViewById(R.id.infoView);
    imgView = (ImageView) findViewById(R.id.cardbg);
    imgView.setBackgroundResource(R.drawable.myanim);
    _animation = (AnimationDrawable) imgView.getBackground();
    _animation.setOneShot(false);
    uiHandler = new MyHandler(this);

    mBluetoothReader = new BluetoothReader();
    mBluetoothReader.setOnReaderStateListener(new BluetoothReader.OnReaderStateListener() {
        @Override
        public void onReaderStateChange(String readerName, int readerState) {
            if (readerName.isEmpty() == false) {
                uiHandler.obtainMessage(READER_MESSAGE, readerState, -1, readerName).sendToTarget();
            }
        }
    });

    View scan = findViewById(R.id.btScan);
    scan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            infoText.setText("Select bluetooth reader for connect...");
            Intent serverIntent = new Intent(TestActivity3.this, DeviceListActivity.class);
            startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
        }
    });
}
 
Example 5
Project: letv   File: ChannelFragmentAdapter.java   Source Code and License Vote up 6 votes
private void startEditMode(RecyclerView parent) {
    this.isEditMode = true;
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View view = parent.getChildAt(i);
        if (view != null) {
            ImageView imgEdit = (ImageView) view.findViewById(R.id.edit_tip);
            RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.item_group_id);
            if (layout != null) {
                layout.setBackgroundResource(R.drawable.channel_wall_item_selecter_bg);
            }
            if (imgEdit != null) {
                if (((Integer) imgEdit.getTag()).intValue() == 0) {
                    imgEdit.setBackgroundResource(2130837812);
                } else {
                    imgEdit.setBackgroundResource(2130837811);
                }
                imgEdit.setVisibility(0);
            }
        }
    }
}
 
Example 6
Project: HutHelper   File: SmallBitmapGridViewAdapter.java   Source Code and License Vote up 6 votes
@Override
public View getView(final int position, final View convertView, ViewGroup parent) {
    ImageView img = new ImageView(context);
    img.setBackgroundResource(R.color.white);
    img.setPadding(2, 2, 2, 2);
    img.setScaleType(ImageView.ScaleType.CENTER_CROP);

    int width = ScreenUtils.getScreenWidth(context) - DensityUtils.dp2px(context, 117);// 获取屏幕宽度
    int height = width = width / 4;// 对当前的列数进行设置imgView的宽度
    img.setLayoutParams(new AbsListView.LayoutParams(width, height));

    Glide
            .with(context)
            .load(Constants.PICTURE_URL + list.get(position))
            .override(width, height)
            .skipMemoryCache(true)
            .centerCrop()
            .crossFade()
            .placeholder(R.drawable.img_loading)
            .error(R.drawable.img_error)
            .into(img);

    return img;
}
 
Example 7
Project: NanoIconPackLite   File: LiteIconActivityV1.java   Source Code and License Vote up 6 votes
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    FrameLayout contentView = new FrameLayout(LiteIconActivityV1.this);
    int gridW = (int) (displayMetrics.density * GRID_W_IN_DP);
    int gridH = (int) (displayMetrics.density * GRID_H_IN_DP);
    ViewGroup.LayoutParams lpCv = new ViewGroup.LayoutParams(gridW, gridH);
    contentView.setLayoutParams(lpCv);

    ImageView ivIcon = new ImageView(LiteIconActivityV1.this);
    ivIcon.setTag("iv");
    ivIcon.setScaleType(ImageView.ScaleType.FIT_CENTER);
    ivIcon.setClickable(true);
    ivIcon.setBackgroundResource(getClickBg());
    int iconSize = (int) (displayMetrics.density * ICON_SIZE_IN_DP);
    FrameLayout.LayoutParams lpIv = new FrameLayout.LayoutParams(iconSize, iconSize);
    lpIv.gravity = Gravity.CENTER;
    ivIcon.setLayoutParams(lpIv);
    contentView.addView(ivIcon);

    return new IconHolder(contentView);
}
 
Example 8
Project: HutHelper   File: AutoScrollViewPager.java   Source Code and License Vote up 6 votes
public void initPointView(int size) {
    layout = new LinearLayout(context);
    for (int i = 0; i < size; i++) {
        ImageView imageView = new ImageView(context);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20, 20);
        params.leftMargin = 8;
        params.gravity = Gravity.CENTER;
        imageView.setLayoutParams(params);
        if (i == 0) {
            imageView.setBackgroundResource(R.drawable.ic_point_checked);
        } else {
            imageView.setBackgroundResource(R.drawable.ic_point_normal);
        }
        layout.addView(imageView);
    }
    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(ALIGN_PARENT_BOTTOM);
    layoutParams.addRule(CENTER_HORIZONTAL);

    layoutParams.setMargins(12, 20, 12, 20);
    layout.setLayoutParams(layoutParams);
    addView(layout);
}
 
Example 9
Project: SuperSelector   File: ViewPagerIndicator.java   Source Code and License Vote up 6 votes
public ViewPagerIndicator(Context context, ViewPager viewPager, LinearLayout dotLayout, int size) {
    this.context = context;
    this.viewPager = viewPager;
    this.dotLayout = dotLayout;
    this.size = size;

    for(int i = 0; i < size; i++){
        ImageView imageView = new ImageView(context);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        params.leftMargin = 10;
        params.rightMargin = 10;
        params.height = imgSize;
        params.width = imgSize;
        if(0 ==i){
            imageView.setBackgroundResource(imgSelected);
        }else {
            imageView.setBackgroundResource(imgNoselect);
        }
        dotLayout.addView(imageView, params);
        dotViewLists.add(imageView);

    }
}
 
Example 10
Project: Paper-Melody   File: MusicHallCycleViewPager.java   Source Code and License Vote up 6 votes
private View getImageView(Context context, String imgUrl) {
    /* 设置某一页面的view */
    RelativeLayout relativeLayout = new RelativeLayout(context);
    ImageView imageView = new ImageView(context);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setLayoutParams(layoutParams);
    // 设置一个半透明的黑色背景,防止白字受白色图片干扰而无法显示
    ImageView background = new ImageView(context);
    background.setLayoutParams(layoutParams);
    background.setBackgroundResource(R.color.colorCycleViewBannerBackground);
    relativeLayout.addView(imageView);
    relativeLayout.addView(background);
    Picasso.with(context).load(imgUrl).into(imageView);
    return relativeLayout;
}
 
Example 11
Project: HutHelper   File: AutoScrollViewPager.java   Source Code and License Vote up 5 votes
public void updatePointView(int position) {
    int size = layout.getChildCount();
    for (int i = 0; i < size; i++) {
        ImageView imageView = (ImageView) layout.getChildAt(i);
        if (i == position) {
            imageView.setBackgroundResource(R.drawable.ic_point_checked);
        } else {
            imageView.setBackgroundResource(R.drawable.ic_point_normal);
        }
    }
}
 
Example 12
Project: boohee_v5.6   File: UserTimelineAdapter.java   Source Code and License Vote up 5 votes
private void initAvatar(ImageView avatar, Post post) {
    String avatar_url = this.user.avatar_url;
    if (post.user != null) {
        avatar_url = post.user.avatar_url;
    }
    if (TextUtils.isEmpty(avatar_url)) {
        avatar.setBackgroundResource(R.drawable.aa0);
    } else {
        this.imageLoader.displayImage(avatar_url, avatar, ImageLoaderOptions.avatar());
    }
    avatar.setOnClickListener(new AvatarClickListener(post));
}
 
Example 13
Project: android-MaterialPillsBox   File: MaterialPillsBox.java   Source Code and License Vote up 5 votes
private LinearLayout setupPillChildView(String pillMessage, boolean isPressed, int imgResource) {
    final LinearLayout lnlContainer = (LinearLayout) LayoutInflater.from(getContext())
            .inflate(R.layout.pills_box_layout, this, false);
    lnlContainer.setBackgroundResource(backgroundPill);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(pillMarginLeft, pillMarginTop, pillMarginRight, pillMarginBottom);
    lnlContainer.setLayoutParams(layoutParams);

    if (isPressed) {
        lnlContainer.setBackgroundResource(backgroundPillSelected);
    } else {
        lnlContainer.setBackgroundResource(backgroundPill);
    }

    //Inflating LinearLayout child for customization
    LinearLayout lnlChild = (LinearLayout) lnlContainer.findViewById(R.id.lnlChild);
    lnlChild.setPadding(pillPaddingLeft, pillPaddingTop, pillPaddingRight, pillPaddingBottom);

    //Inflating ImageView
    CirculateImageView civContact = (CirculateImageView) lnlContainer.findViewById(R.id.civContact);

    if (hideContactIcon) {
        civContact.setVisibility(View.VISIBLE);
    } else {
        civContact.setVisibility(View.GONE);
    }

    if (imgResource == 0) {
        civContact.setImageResource(R.drawable.ic_orbismobile);
    } else {
        civContact.setImageResource(imgResource);
    }
    //Inflating TextView child for customization
    TextView lblMessage = (TextView) lnlContainer.findViewById(R.id.lblMessage);
    lblMessage.setText(pillMessage);
    lblMessage.setTextColor(pillTextColor);
    //Inflating imgClose view for customization
    ImageView imgClose = (ImageView) lnlContainer.findViewById(R.id.imgClose);
    imgClose.setBackgroundResource(pillCloseIcon);
    if (hideCloseIcon) {
        imgClose.setVisibility(View.VISIBLE);
    } else {
        imgClose.setVisibility(View.GONE);
    }
    MarginLayoutParams marginLayoutParams = (MarginLayoutParams) imgClose.getLayoutParams();
    marginLayoutParams.leftMargin = closeIconMarginLeft;
    imgClose.setLayoutParams(marginLayoutParams);
    imgClose.setOnClickListener(this);
    lnlContainer.setOnClickListener(this);
    return lnlContainer;
}
 
Example 14
Project: android-project-gallery   File: LocalAlbumActivity.java   Source Code and License Vote up 5 votes
@Override
public void onBindViewHolder(RecyclerViewAdapter.RecyclerViewHolder holder, int position)
{
	LocalAlbumActivity activity = mWeakReference.get();
	ImageView image = holder.findViewById(R.id.image);
	ImageView background = holder.findViewById(R.id.background);
	TextView name_number = holder.findViewById(R.id.name_number);
	
	AlbumInfo albumInfo = activity.mImageAdapter.getItem(position);
	name_number.setText(activity.getString(R.string.name_number, albumInfo.getName(), albumInfo.getPicnum()));
	background.setBackgroundResource(IMAGE_BACKGROUND[position % IMAGE_BACKGROUND.length]);
	activity.mImageLoader.displayImage(albumInfo.getCoverurl(), image, activity.mOptions);
}
 
Example 15
Project: boohee_v5.6   File: FollowListPage.java   Source Code and License Vote up 5 votes
public void onCreate() {
    LinearLayout llPage = new LinearLayout(getContext());
    llPage.setBackgroundColor(-657931);
    llPage.setOrientation(1);
    this.activity.setContentView(llPage);
    this.llTitle = new TitleLayout(getContext());
    int resId = R.getBitmapRes(getContext(), "title_back");
    if (resId > 0) {
        this.llTitle.setBackgroundResource(resId);
    }
    this.llTitle.getBtnBack().setOnClickListener(this);
    resId = R.getStringRes(getContext(), "multi_share");
    if (resId > 0) {
        this.llTitle.getTvTitle().setText(resId);
    }
    this.llTitle.getBtnRight().setVisibility(0);
    resId = R.getStringRes(getContext(), SportPlanFragment.COURSE_STATUS_FINISH);
    if (resId > 0) {
        this.llTitle.getBtnRight().setText(resId);
    }
    this.llTitle.getBtnRight().setOnClickListener(this);
    this.llTitle.setLayoutParams(new LayoutParams(-1, -2));
    llPage.addView(this.llTitle);
    FrameLayout flPage = new FrameLayout(getContext());
    LayoutParams lpFl = new LayoutParams(-1, -2);
    lpFl.weight = 1.0f;
    flPage.setLayoutParams(lpFl);
    llPage.addView(flPage);
    PullToRefreshView followList = new PullToRefreshView(getContext());
    followList.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
    flPage.addView(followList);
    this.adapter = new FollowAdapter(followList);
    this.adapter.setPlatform(this.platform);
    followList.setAdapter(this.adapter);
    this.adapter.getListView().setOnItemClickListener(this);
    ImageView ivShadow = new ImageView(getContext());
    resId = R.getBitmapRes(getContext(), "title_shadow");
    if (resId > 0) {
        ivShadow.setBackgroundResource(resId);
    }
    ivShadow.setLayoutParams(new FrameLayout.LayoutParams(-1, -2));
    flPage.addView(ivShadow);
    followList.performPulling(true);
}
 
Example 16
Project: TrainAppTFG   File: RecogerDatosRecogida.java   Source Code and License Vote up 5 votes
@Override
public void handleMessage(Message msg) {
    int re = (Integer)msg.obj;

    ImageView imagen = (ImageView) consejo.findViewById(R.id.imageView_colocacion);

    if(re == 0){
        imagen.setBackgroundResource(R.drawable.colocacion);
    }
    else if(re == 1){
        imagen.setBackgroundResource(R.drawable.colocacionmal);
    }

}
 
Example 17
Project: TrainAppTFG   File: ReconocerActividadFragment.java   Source Code and License Vote up 5 votes
@Override
public void handleMessage(Message msg) {
    int re = (Integer)msg.obj;

    ImageView imagen = (ImageView) consejo.findViewById(R.id.imageView_colocacion);

    if(re == 0){
        imagen.setBackgroundResource(R.drawable.colocacion);
    }
    else if(re == 1){
        imagen.setBackgroundResource(R.drawable.colocacionmal);
    }

}
 
Example 18
Project: FaceAI_Android   File: MyImageAdapter.java   Source Code and License Vote up 5 votes
@Override
public View getView(int position, View convertView, ViewGroup parent) {

	ImageView imageView = new ImageView(context);
	imageView.setBackgroundResource(image[position % 13]);
	imageView.setLayoutParams(new Gallery.LayoutParams(400, 300));
	imageView.setScaleType(ScaleType.FIT_XY);

	return imageView;
}
 
Example 19
Project: android-project-gallery   File: WelcomeActivity.java   Source Code and License Vote up 4 votes
@Override
public Object instantiateItem(ViewGroup container, int position)
{
	View imageLayout = mInflater.inflate(R.layout.app_welcome_item, container, false);
	ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
	Button button = (Button) imageLayout.findViewById(R.id.button);
	if (MODE_WELCOME.equalsIgnoreCase(mMode) && position < WELCOME_PAGES.length - 1)
	{
		// Welcome mode.
		button.setVisibility(View.GONE);
	}
	else if (MODE_PERSONAL_TAILOR.equalsIgnoreCase(mMode))
	{
		// Personal tailor.
		button.setVisibility(View.GONE);
	}
	
	button.setOnClickListener(new OnClickListener()
	{
		
		@Override
		public void onClick(View v)
		{
			if (MODE_WELCOME.equalsIgnoreCase(mMode))
			{
				// Welcome mode.
				gotoHomeActivity();
			}
			else if (MODE_PERSONAL_TAILOR.equalsIgnoreCase(mMode))
			{
				// Personal tailor.
				//gotoPersonalTailorActivity();
			}
		}
	});

	imageView.setBackgroundResource(WELCOME_PAGES[position]);
	container.addView(imageLayout, 0);
	
	return imageLayout;
}
 
Example 20
Project: GitHub   File: MainActivity.java   Source Code and License Vote up 3 votes
private  View buildIndicator(Tab tab){


        View view =mInflater.inflate(R.layout.tab_indicator,null);
        ImageView img = (ImageView) view.findViewById(R.id.icon_tab);
        TextView text = (TextView) view.findViewById(R.id.txt_indicator);

        img.setBackgroundResource(tab.getIcon());
        text.setText(tab.getTitle());

        return  view;
    }