当前位置: 首页>>代码示例>>Java>>正文


Java ImageButton.setBackground方法代码示例

本文整理汇总了Java中android.widget.ImageButton.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java ImageButton.setBackground方法的具体用法?Java ImageButton.setBackground怎么用?Java ImageButton.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.ImageButton的用法示例。


在下文中一共展示了ImageButton.setBackground方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: showActions

import android.widget.ImageButton; //导入方法依赖的package包/类
/**
 * This updates the buttons on the controller view to show actions that
 * aren't included in the declared supported actions in red to more easily
 * detect potential bugs.
 *
 * @param actions The mask of currently supported actions from {@see
 *                PlaybackStateCompat.getActions()}.
 */
private void showActions(@PlaybackStateCompat.Actions long actions) {
    final int count = mActionViewIdMap.size();
    for (int i = 0; i < count; ++i) {
        final int viewId = mActionViewIdMap.keyAt(i);
        final long action = mActionViewIdMap.valueAt(i);

        final ImageButton button = mActionButtonMap.get(viewId);
        if (actionSupported(actions, action)) {
            button.setBackground(null);
        } else {
            button.setBackgroundResource(R.drawable.bg_unsuported_action);
        }
    }

    final boolean shuffleEnabled =
            mController.getShuffleMode() == PlaybackStateCompat.SHUFFLE_MODE_ALL ||
                    mController.getShuffleMode() == PlaybackStateCompat.SHUFFLE_MODE_GROUP;
    final int shuffleTint = shuffleEnabled
            ? ContextCompat.getColor(this, R.color.colorPrimary)
            : ContextCompat.getColor(this, R.color.colorInactive);
    DrawableCompat.setTint(mShuffleToggle.getDrawable(), shuffleTint);
}
 
开发者ID:googlesamples,项目名称:android-media-controller,代码行数:31,代码来源:MediaAppControllerActivity.java

示例2: chooseFormLeftElem

import android.widget.ImageButton; //导入方法依赖的package包/类
public void chooseFormLeftElem(String newColorKey, ImageButton imageButton) {
    normal = (ContextCompat.getDrawable(getContext(), R.drawable.left_oval_selector));
    red = (ContextCompat.getDrawable(getContext(), R.drawable.left_2_red));

    if (newColorKey.equals(getContext().getString(R.string.pref_color_red_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.left_oval_selector_red));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_initial_value))) {
        imageButton.setBackground(normal);
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_orange_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.left_oval_selector_orange));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_yellow_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.left_oval_selector_yellow));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_grey_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.left_oval_selector_grey));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_rhomb_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.left_rhomb_selector));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_hexagon_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.left_hexagon_selector));
    }
}
 
开发者ID:Existentio,项目名称:OddLauncher,代码行数:21,代码来源:SettingsHelper.java

示例3: chooseFormRightElem

import android.widget.ImageButton; //导入方法依赖的package包/类
public void chooseFormRightElem(String newColorKey, ImageButton imageButton) {
    normal = (ContextCompat.getDrawable(getContext(), R.drawable.right_oval_selector));
    red = (ContextCompat.getDrawable(getContext(), R.drawable.right_2_red));

    if (newColorKey.equals(getContext().getString(R.string.pref_color_red_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.right_oval_selector_red));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_initial_value))) {
        imageButton.setBackground(normal);
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_orange_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.right_oval_selector_orange));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_yellow_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.right_oval_selector_yellow));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_grey_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.right_oval_selector_grey));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_rhomb_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.right_rhomb_selector));
    } else if (newColorKey.equals(getContext().getString(R.string.pref_color_label_hexagon_value))) {
        imageButton.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.right_hexagon_selector));
    }
}
 
开发者ID:Existentio,项目名称:OddLauncher,代码行数:21,代码来源:SettingsHelper.java

示例4: onCreateView

import android.widget.ImageButton; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View dialogView =  inflater.inflate(R.layout.dialog_image_source_select, container);

    mCamera = (ImageButton) dialogView.findViewById(R.id.dialog_image_source_select_camera);
    mGallery = (ImageButton) dialogView.findViewById(R.id.dialog_image_source_select_gallery);
    mCancel = (Button) dialogView.findViewById(R.id.dialog_image_source_select_cancel);

    if(mCameraDrawable != null)
        mCamera.setBackground(mCameraDrawable);

    if(mGalleryDrawable != null)
        mGallery.setBackground(mGalleryDrawable);

    mCamera.setOnClickListener(this);
    mGallery.setOnClickListener(this);
    mCancel.setOnClickListener(this);

    return dialogView;
}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:22,代码来源:SelectImageSourceDialogFragment.java

示例5: instantiateItem

import android.widget.ImageButton; //导入方法依赖的package包/类
public Object instantiateItem(ViewGroup container, int position) {
    LayoutInflater inflater = (LayoutInflater) QuickLaunchView.this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout pageView = (LinearLayout) inflater.inflate(R.layout.shade_quick_launch_page, null);
    for (int i = position * 5; i < (position * 5) + 5; i++) {
        ImageButton button = (ImageButton) inflater.inflate(R.layout.quicklaunch_button, null);
        button.setScaleType(ScaleType.FIT_CENTER);
        if (i < this.quickLaunchApps.size()) {
            final App app = (App) this.quickLaunchApps.get(i);
            button.setImageDrawable(app.getAppIcon());
            button.setOnClickListener(new OnClickListener() {
                public void onClick(View view) {
                    ((InboxViewManager) GuiceModule.get().getInstance(InboxViewManager.class)).closeDrawer();
                    LockScreenManager lockScreenManager = (LockScreenManager) GuiceModule.get().getInstance(LockScreenManager.class);
                    if (lockScreenManager.isPhoneLocked()) {
                        lockScreenManager.unlockAndLaunchApp(app);
                    } else {
                        QuickLaunchView.this.appManager.launchAppWithBackButton(app, AppLaunchMethod.Quicklaunch);
                    }
                }
            });
        } else {
            button.setBackground(null);
            button.setOnClickListener(null);
        }
        pageView.addView(button, new LayoutParams(-1, -1, 0.5f));
    }
    container.addView(pageView);
    return pageView;
}
 
开发者ID:bunnyblue,项目名称:NoticeDog,代码行数:30,代码来源:QuickLaunchView.java

示例6: InfoBarLayout

import android.widget.ImageButton; //导入方法依赖的package包/类
/**
 * Constructs a layout for the specified infobar. After calling this, be sure to set the
 * message, the buttons, and/or the custom content using setMessage(), setButtons(), and
 * setCustomContent().
 *
 * @param context The context used to render.
 * @param infoBarView InfoBarView that listens to events.
 * @param iconResourceId ID of the icon to use for the infobar.
 * @param iconBitmap Bitmap for the icon to use, if the resource ID wasn't passed through.
 * @param message The message to show in the infobar.
 */
public InfoBarLayout(Context context, InfoBarView infoBarView, int iconResourceId,
        Bitmap iconBitmap, CharSequence message) {
    super(context);
    mControlLayouts = new ArrayList<InfoBarControlLayout>();

    mInfoBarView = infoBarView;

    // Cache resource values.
    Resources res = getResources();
    mSmallIconSize = res.getDimensionPixelSize(R.dimen.infobar_small_icon_size);
    mSmallIconMargin = res.getDimensionPixelSize(R.dimen.infobar_small_icon_margin);
    mBigIconSize = res.getDimensionPixelSize(R.dimen.infobar_big_icon_size);
    mBigIconMargin = res.getDimensionPixelSize(R.dimen.infobar_big_icon_margin);
    mMarginAboveButtonGroup =
            res.getDimensionPixelSize(R.dimen.infobar_margin_above_button_row);
    mMarginAboveControlGroups =
            res.getDimensionPixelSize(R.dimen.infobar_margin_above_control_groups);
    mPadding = res.getDimensionPixelOffset(R.dimen.infobar_padding);
    mMinWidth = res.getDimensionPixelSize(R.dimen.infobar_min_width);
    mAccentColor = ApiCompatibilityUtils.getColor(res, R.color.infobar_accent_blue);

    // Set up the close button. Apply padding so it has a big touch target.
    mCloseButton = new ImageButton(context);
    mCloseButton.setId(R.id.infobar_close_button);
    mCloseButton.setImageResource(R.drawable.btn_close);
    TypedArray a = getContext().obtainStyledAttributes(
            new int [] {R.attr.selectableItemBackground});
    Drawable closeButtonBackground = a.getDrawable(0);
    a.recycle();
    mCloseButton.setBackground(closeButtonBackground);
    mCloseButton.setPadding(mPadding, mPadding, mPadding, mPadding);
    mCloseButton.setOnClickListener(this);
    mCloseButton.setContentDescription(res.getString(R.string.infobar_close));
    mCloseButton.setLayoutParams(new LayoutParams(0, -mPadding, -mPadding, -mPadding));

    // Set up the icon.
    if (iconResourceId != 0 || iconBitmap != null) {
        mIconView = new ImageView(context);
        if (iconResourceId != 0) {
            mIconView.setImageResource(iconResourceId);
        } else if (iconBitmap != null) {
            mIconView.setImageBitmap(iconBitmap);
        }
        mIconView.setLayoutParams(new LayoutParams(0, 0, mSmallIconMargin, 0));
        mIconView.getLayoutParams().width = mSmallIconSize;
        mIconView.getLayoutParams().height = mSmallIconSize;
        mIconView.setFocusable(false);
    }

    // Set up the message view.
    mMessageMainText = message;
    mMessageLayout = new InfoBarControlLayout(context);
    mMessageTextView = mMessageLayout.addMainMessage(prepareMainMessageString());
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:66,代码来源:InfoBarLayout.java

示例7: addButton

import android.widget.ImageButton; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void addButton(@NonNull final Button button, @NonNull final ActionListener thisListener)
{
	// interface button to implementation
	final String name = button.name();
	final ButtonImplementation impl = ButtonImplementation.valueOf(name);

	// new button
	final ImageButton imageButton = new ImageButton(getContext());
	imageButton.setLayoutParams(new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

	// drawable
	final int thisIconIndex = impl.getIconIndex();
	final Drawable bitmapDrawable = this.drawables[thisIconIndex];

	// tint drawable
	Utils.tint(bitmapDrawable, this.iconTint);

	// button drawable
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
	{
		imageButton.setBackground(bitmapDrawable);
	}
	else
	{
		imageButton.setBackgroundDrawable(bitmapDrawable);
	}

	// listener
	imageButton.setOnClickListener(thisListener::onAction);

	// add
	this.panel.addView(imageButton, this.layoutParams);
}
 
开发者ID:1313ou,项目名称:TreebolicLib,代码行数:36,代码来源:Toolbar.java

示例8: ScreenSharingBar

import android.widget.ImageButton; //导入方法依赖的package包/类
public ScreenSharingBar(Context context, ScreenSharingBarListener listener) {
    super(context);

    this.mListener = listener;
    this.setBackgroundColor(getResources().getColor(R.color.screensharing_bar));

    mCloseBtn = new ImageButton(context);
    mCloseBtn.setImageDrawable(getResources().getDrawable(R.drawable.close));

    mCloseBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mListener.onClose();
        }
    });
    mCloseBtn.setBackground(null);
    mCloseBtn.setClickable(true);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);

    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    this.addView(mCloseBtn, params);

    mTextView = new TextView(context);
    mTextView.setText(R.string.screensharing_text);
    params = new RelativeLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    params.addRule(CENTER_HORIZONTAL);
    params.addRule(CENTER_VERTICAL);

    this.addView(mTextView, params);
}
 
开发者ID:opentok,项目名称:accelerator-sample-apps-android,代码行数:36,代码来源:ScreenSharingBar.java

示例9: onCreateView

import android.widget.ImageButton; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i(LOGTAG, "OnCreate ActionBarFragment");

    rootView = inflater.inflate(R.layout.actionbar_fragment, container, false);
    mAudioBtn = (ImageButton) rootView.findViewById(R.id.localAudio);
    mVideoBtn = (ImageButton) rootView.findViewById(R.id.localVideo);
    mCallBtn = (ImageButton) rootView.findViewById(R.id.call);
    mScreenSharingBtn = (ImageButton) rootView.findViewById(R.id.screenSharing);
    mAnnotationsBtn = (ImageButton) rootView.findViewById(R.id.annotations);
    mTextChatBtn = (ImageButton) rootView.findViewById(R.id.textchat);
    mUnreadMessages = (ImageButton) rootView.findViewById(R.id.unread_messages);

    drawableStartCall = VectorDrawableCompat.create(getResources(), R.drawable.initiate_call_button, null);
    drawableEndCall = VectorDrawableCompat.create(getResources(), R.drawable.end_call_button, null);
    drawableBckBtn = VectorDrawableCompat.create(getResources(), R.drawable.bckg_icon, null);

    mAudioBtn.setImageResource(mActivity.getWrapper().isLocalMediaEnabled(MediaType.AUDIO)
            ? R.drawable.mic_icon
            : R.drawable.muted_mic_icon);
    mAudioBtn.setBackground(drawableBckBtn);

    mVideoBtn.setImageResource(mActivity.getWrapper().isLocalMediaEnabled(MediaType.VIDEO)
            ? R.drawable.video_icon
            : R.drawable.no_video_icon);
    mVideoBtn.setBackground(drawableBckBtn);

    mCallBtn.setImageResource(mActivity.isCallInProgress()
            ? R.drawable.hang_up
            : R.drawable.start_call);

    mCallBtn.setBackground(mActivity.isCallInProgress()
            ? drawableEndCall
            : drawableStartCall);

    mCallBtn.setOnClickListener(mBtnClickListener);

    setEnabled(mActivity.isCallInProgress());

    return rootView;
}
 
开发者ID:opentok,项目名称:accelerator-sample-apps-android,代码行数:43,代码来源:ActionBarFragment.java


注:本文中的android.widget.ImageButton.setBackground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。