android.widget.ImageButton# setImageResource ( ) 源码实例Demo

下面列出了android.widget.ImageButton# setImageResource ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: kute   文件: PersonDetail.java

public Boolean handleOtherDetailsDropdown(Boolean is_otherdetail_dropdown, ImageButton icon, final TableRow other_details_text) {
    if (is_otherdetail_dropdown) {
        other_details_text.setVisibility(View.GONE);
        icon.setImageResource(R.drawable.ic_arrow_drop_down_black_24dp);
        return false;
    } else {
        other_details_text.setVisibility(View.VISIBLE);
        icon.setImageResource(R.drawable.ic_arrow_drop_up_black_24dp);
        //Adjusting the scrollview for smaller screens
        scroll_view.post(new Runnable() {
            @Override
            public void run() {
                scroll_view.scrollTo(0, other_details_text.getBottom());
            }
        });
        return true;
    }
}
 

private void configureButtonContent(View button, ExpandableItem expandableItem) {
  if (expandableItem.hasBackgroundId()) {
    int backgroundId = expandableItem.getBackgroundId();
    button.setBackgroundResource(backgroundId);
  }
  if (expandableItem.hasTitle()) {
    String text = expandableItem.getTitle();
    ((Button) button).setText(text);
  }
  if (expandableItem.hasResourceId()) {
    ImageButton imageButton = (ImageButton) button;
    int resourceId = expandableItem.getResourceId();
    imageButton.setImageResource(resourceId);
  }
}
 
源代码3 项目: Conquer   文件: NotifyUtils.java

public static void pauseAudio(ImageButton ib_play) {
	// 暂停播放,保存播放进度
	if (player != null && player.isPlaying()) {
		curPosition = player.getCurrentPosition();
		player.pause();
		if (timer_play != null) {
			timer_play.cancel();
			timer_play = null;
		}
		if (ib_play != null) {
			ib_play.setImageResource(R.drawable.play_audio);
			ib_play.setTag("play");
		}
	}
}
 

private void addIconTab(final int position, int resId) {

        ImageButton tab = new ImageButton(getContext());
        tab.setImageResource(resId);
        tab.setFocusable(true);
        addTab(position, tab);
        tab.setSelected(position == currentPosition);
    }
 
源代码5 项目: ki4a   文件: MainActivity.java

protected static void refresh_status_img(int status)
{
    button = (ImageButton) myMainActivity.findViewById(R.id.imageButton_status);
    text_status = (TextView) myMainActivity.findViewById(R.id.textView_status);
    if(status==Util.STATUS_DISCONNECT)
    {
        text_status.setText(R.string.text_status_empty);
        button.setImageResource(R.drawable.status_red);
    }
    else if(status==Util.STATUS_INIT)
    {
        text_status.setText(R.string.text_status_initializing);
        button.setImageResource(R.drawable.status_gray);
    }
    else if(status==Util.STATUS_CONNECTING)
    {
        text_status.setText(R.string.text_status_connecting);
        button.setImageResource(R.drawable.status_orange);
    }
    else if(status==Util.STATUS_SOCKS)
    {
        text_status.setText(R.string.text_status_connected);
        button.setImageResource(R.drawable.status_blue);
        if (adClientView != null) {
            adClientView.load();
        }
    }
}
 

public RichEditWidgetView(Context context, AttributeSet attrs, int defStyleAttr){
	super(context, attrs, defStyleAttr);
	View view = LayoutInflater.from(context).inflate(R.layout.view_rich_edit_widget, this, true);
	ButterKnife.bind(this, view);
	setVisibility(GONE);
	for (int i = 0; i < supportedEffects.length; i++){
		LayoutInflater.from(context).inflate(R.layout.view_rich_edit_action_button, linearLayout, true);
		ImageButton action = (ImageButton) linearLayout.getChildAt(linearLayout.getChildCount() - 1);
		action.setTag(supportedEffects[i]);
		action.setImageResource(effectIcons[i]);
		action.setOnClickListener(actionClickListener);
	}
}
 

private void setupImageButtonListeners(ImageButton... imageButtons) {
    for(ImageButton b : imageButtons) {
        if(b != null) {
            Button info = Buttons.getButton(b.getId(), Preferences.get(b.getContext()));
            b.setImageResource(info.getIconId());
            b.setContentDescription(b.getContext().getString(info.getContentDescriptionId()));
            b.setOnClickListener(this);
            b.setOnLongClickListener(this);
        }
    }
}
 
源代码8 项目: ticdesign   文件: DatetimePickerDialog.java

private void updateButton() {
    ImageButton button = getIconButton(BUTTON_POSITIVE);
    if (button != null) {
        int iconResId;
        if (mOnLastPage) {
            iconResId = mLastBtnIconResId > 0 ? mLastBtnIconResId : R.drawable.tic_ic_btn_ok;
        } else {
            iconResId = mNextBtnIconResId > 0 ? mNextBtnIconResId : R.drawable.tic_ic_btn_next;
        }
        button.setImageResource(iconResId);
        button.setOnClickListener(this);
    }
}
 
源代码9 项目: Jreader   文件: ReadActivity.java

/**
 * popupwindow的弹出,工具栏
 */
public void pop() {

    mPopupWindow.showAtLocation(mPageWidget, Gravity.NO_GRAVITY, 0, 0);
    fontSize = (TextView) popupwindwow.findViewById(R.id.bookBtn_size);
    readLight = (TextView) popupwindwow.findViewById(R.id.bookBtn_light);
    bookMark = (TextView) popupwindwow.findViewById(R.id.bookBtn_mark);
    readJump = (TextView) popupwindwow.findViewById(R.id.bookBtn_jump);
    readSet = (TextView) popupwindwow.findViewById(R.id.readSet);
    layout = (LinearLayout) popupwindwow.findViewById(R.id.bookpop_bottom);//主要为了夜间模式时设置背景
    fontSize.setTypeface(typeface);//设置字体
    readLight.setTypeface(typeface);
    bookMark.setTypeface(typeface);
    readJump.setTypeface(typeface);
    readSet.setTypeface(typeface);

    TextView blank_view = (TextView) popupwindwow.findViewById(R.id.blank_view);
    listener_book = (ImageButton) popupwindwow.findViewById(R.id.listener_book);
    pop_return = (ImageButton) popupwindwow.findViewById(R.id.pop_return);
    imageBtn_light = (ImageButton) popupwindwow.findViewById((R.id.imageBtn_light));
    getDayOrNight();
    if (isNight) {
        layout.setBackgroundResource(R.drawable.tmall_bar_bg);
        imageBtn_light.setImageResource(R.drawable.menu_light_icon2);
    } else {
        layout.setBackgroundResource(R.drawable.tmall_bar_bg);
        imageBtn_light.setImageResource(R.drawable.menu_daynight_icon);
    }
    fontSize.setOnClickListener(this);
    readLight.setOnClickListener(this);
    bookMark.setOnClickListener(this);
    readJump.setOnClickListener(this);
    readSet.setOnClickListener(this);
    blank_view.setOnClickListener(this);
    listener_book.setOnClickListener(this);
    pop_return.setOnClickListener(this);
    imageBtn_light.setOnClickListener(this);
}
 

private void init(Context context) {

        Resources resources = getResources();
        int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources);
        this.mDiameter = diameterPX;
        mBtn = new ImageButton(context);
        LayoutParams btnLp = new LayoutParams(diameterPX, diameterPX);
        btnLp.gravity = Gravity.CENTER_HORIZONTAL;
        btnLp.bottomMargin = Util.dpToPx(mGapSize, resources);
        mBtn.setLayoutParams(btnLp);
        OvalShape ovalShape = new OvalShape();
        ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape);
        shapeDrawable.getPaint().setColor(resources.getColor(mMenuItem.getBgColor()));
        mBtn.setBackgroundDrawable(shapeDrawable);
        mBtn.setImageResource(mMenuItem.getIcon());
        mBtn.setClickable(false);
        addView(mBtn);

        mLabel = new TextView(context);
        LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        labelLp.gravity = Gravity.CENTER_HORIZONTAL;
        mLabel.setLayoutParams(labelLp);
        mLabel.setText(mMenuItem.getLabel());
        mLabel.setTextColor(resources.getColor(mMenuItem.getTextColor()));
        mLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize);
        addView(mLabel);

        setOrientation(LinearLayout.VERTICAL);
        if(mAlphaAnimation) {
            setAlpha(0);
        }

        getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                getViewTreeObserver().removeGlobalOnLayoutListener(this);
                applyPressAnimation();
                ViewGroup parent = (ViewGroup) getParent();
                parent.setClipChildren(false);
                parent.setClipToPadding(false);
                setClipChildren(false);
                setClipToPadding(false);
            }
        });


    }
 
源代码11 项目: Swiftnotes   文件: NoteAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    // Inflate custom note view if null
    if (convertView == null)
        convertView = this.inflater.inflate(R.layout.list_view_note, parent, false);

    // Initialize layout items
    RelativeLayout relativeLayout = (RelativeLayout) convertView.findViewById(R.id.relativeLayout);
    LayerDrawable roundedCard = (LayerDrawable) context.getResources().getDrawable(R.drawable.rounded_card);
    TextView titleView = (TextView) convertView.findViewById(R.id.titleView);
    TextView bodyView = (TextView) convertView.findViewById(R.id.bodyView);
    ImageButton favourite = (ImageButton) convertView.findViewById(R.id.favourite);

    // Get Note object at position
    JSONObject noteObject = getItem(position);

    if (noteObject != null) {
        // If noteObject not empty -> initialize variables
        String title = context.getString(R.string.note_title);
        String body = context.getString(R.string.note_body);
        String colour = String.valueOf(context.getResources().getColor(R.color.white));
        int fontSize = 18;
        Boolean hideBody = false;
        Boolean favoured = false;

        try {
            // Get noteObject data and store in variables
            title = noteObject.getString(NOTE_TITLE);
            body = noteObject.getString(NOTE_BODY);
            colour = noteObject.getString(NOTE_COLOUR);

            if (noteObject.has(NOTE_FONT_SIZE))
                fontSize = noteObject.getInt(NOTE_FONT_SIZE);

            if (noteObject.has(NOTE_HIDE_BODY))
                hideBody = noteObject.getBoolean(NOTE_HIDE_BODY);

            favoured = noteObject.getBoolean(NOTE_FAVOURED);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        // Set favourite image resource
        if (favoured)
            favourite.setImageResource(R.drawable.ic_fav);

        else
            favourite.setImageResource(R.drawable.ic_unfav);


        // If search or delete modes are active -> hide favourite button; Show otherwise
        if (searchActive || deleteActive)
            favourite.setVisibility(View.INVISIBLE);

        else
            favourite.setVisibility(View.VISIBLE);


        titleView.setText(title);

        // If hidBody is true -> hide body of note
        if (hideBody)
            bodyView.setVisibility(View.GONE);

        // Else -> set visible note body, text to normal and set text size to 'fontSize' as sp
        else {
            bodyView.setVisibility(View.VISIBLE);
            bodyView.setText(body);
            bodyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSize);
        }

        // If current note is selected for deletion -> highlight
        if (checkedArray.contains(position)) {
            ((GradientDrawable) roundedCard.findDrawableByLayerId(R.id.card))
                    .setColor(context.getResources().getColor(R.color.theme_primary));
        }

        // If current note is not selected -> set background colour to normal
        else {
            ((GradientDrawable) roundedCard.findDrawableByLayerId(R.id.card))
                    .setColor(Color.parseColor(colour));
        }

        // Set note background style to rounded card
        relativeLayout.setBackground(roundedCard);

        final Boolean finalFavoured = favoured;
        favourite.setOnClickListener(new View.OnClickListener() {
            // If favourite button was clicked -> change that note to favourite or un-favourite
            @Override
            public void onClick(View v) {
                setFavourite(context, !finalFavoured, position);
            }
        });
    }

    return convertView;
}
 
源代码12 项目: NoiseCapture   文件: MeasurementActivity.java

@Override
public void onClick(View v) {
    Resources resources = activity.getResources();
    ImageButton buttonPause= (ImageButton) activity.findViewById(R.id.pauseBtn);
    buttonPause.setEnabled(true);
    ImageButton buttonrecord= (ImageButton) activity.findViewById(R.id.recordBtn);

    if (!activity.measurementService.isStoring()) {
        // Start recording
        buttonrecord.setImageResource(R.drawable.button_record_pressed);
        buttonrecord.setEnabled(false);
        activity.measurementService.startStorage();
        // Force service to stay alive even if this activity is killed (Foreground service)
        activity.startService(new Intent(activity, MeasurementService.class));
    } else {
        // Stop measurement
        activity.measurementService.stopRecording();

        // Show computing progress dialog
        ProgressDialog myDialog = new ProgressDialog(activity);
        if (!activity.measurementService.isCanceled()) {
            myDialog.setMessage(resources.getString(R.string.measurement_processlastsamples,
                    activity.measurementService.getAudioProcess().getRemainingNotProcessSamples()));
            myDialog.setCancelable(false);
            myDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                    resources.getText(R.string.text_CANCEL_data_transfer),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            activity.measurementService.cancel();
                        }
                    });
            myDialog.show();
        }

        // Launch processing end activity
        new Thread(new WaitEndOfProcessing(activity, myDialog)).start();
    }
    activity.initGuiState();
}
 

private void a(int i1, int j1)
{
    ImageButton imagebutton = new ImageButton(getContext());
    imagebutton.setImageResource(j1);
    a(i1, ((View) (imagebutton)));
}
 

private void addIconTab(final int position, int resId) {

		ImageButton tab = new ImageButton(getContext());
		tab.setImageResource(resId);

		addTab(position, tab);

	}
 

private void addIconTab(final int position, int resId) {

        ImageButton tab = new ImageButton(getContext());
        tab.setImageResource(resId);

        addTab(position, tab);

    }
 

private void addIconTab(final int position, int resId) {

        ImageButton tab = new ImageButton(getContext());
        tab.setImageResource(resId);

        addTab(position, tab);

    }
 
源代码17 项目: AndroidBase   文件: PagerSlidingTabStrip.java

private void addIconTab(final int position, int resId) {

		ImageButton tab = new ImageButton(getContext());
		tab.setImageResource(resId);

		addTab(position, tab);

	}
 
源代码18 项目: SuperToasts   文件: TabStrip.java

private void addIconTab(final int position, int resId) {

        ImageButton tab = new ImageButton(getContext());
        tab.setImageResource(resId);

        addTab(position, tab);
    }
 

private void addIconTab(final int position, int resId) {

        ImageButton tab = new ImageButton(getContext());
        tab.setImageResource(resId);

        addTab(position, tab);

    }
 

private void addIconTab(final int position, int resId) {

		ImageButton tab = new ImageButton(getContext());
		tab.setImageResource(resId);

		addTab(position, tab);

	}