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


Java ImageButton.setId方法代码示例

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


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

示例1: getMenuItemView

import android.widget.ImageButton; //导入方法依赖的package包/类
private View getMenuItemView(MenuItem item) {
  final ImageButton button = new ImageButton(context);
  button.setImageDrawable(item.getIcon());
  button.setBackgroundResource(R.drawable.toolbar_button);
  button.setId(item.getItemId());
  button.setLayoutParams(new LayoutParams(itemWidth,
      ViewGroup.LayoutParams.MATCH_PARENT));
  button.setOnClickListener(this);
  button.setOnLongClickListener(this);
  return button;
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:12,代码来源:AyahToolBar.java

示例2: buildBottomBarButton

import android.widget.ImageButton; //导入方法依赖的package包/类
/**
 * Builds an {@link ImageButton} from the data in this params. Generated buttons should be
 * placed on the bottom bar. The button's tag will be its id.
 * @param parent The parent that the inflated {@link ImageButton}.
 * @param listener {@link OnClickListener} that should be used with the button.
 * @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid.
 */
ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) {
    if (mIsOnToolbar) return null;

    ImageButton button = (ImageButton) LayoutInflater.from(context)
            .inflate(R.layout.custom_tabs_bottombar_item, parent, false);
    button.setId(mId);
    button.setImageBitmap(mIcon);
    button.setContentDescription(mDescription);
    if (mPendingIntent == null) {
        button.setEnabled(false);
    } else {
        button.setOnClickListener(listener);
    }
    button.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            final int screenWidth = view.getResources().getDisplayMetrics().widthPixels;
            final int screenHeight = view.getResources().getDisplayMetrics().heightPixels;
            final int[] screenPos = new int[2];
            view.getLocationOnScreen(screenPos);
            final int width = view.getWidth();

            Toast toast = Toast.makeText(
                    view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.BOTTOM | Gravity.END,
                    screenWidth - screenPos[0] - width / 2,
                    screenHeight - screenPos[1]);
            toast.show();
            return true;
        }
    });
    return button;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:41,代码来源:CustomButtonParams.java

示例3: 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

示例4: addTab

import android.widget.ImageButton; //导入方法依赖的package包/类
public void addTab(@DrawableRes int iconId, @IdRes int id, OnClickListener onClickListener) {
        ImageButton view = (ImageButton) mInflater.inflate(R.layout.item_tab_icon, mLayout, false);
        view.setImageResource(iconId);
        view.setId(id);
        view.setOnClickListener(onClickListener);
        mLayout.addView(view, mLayout.getChildCount());
        //滑到最右边
//        this.postDelayed(() -> this.smoothScrollBy(1000, 0), 5);
        this.postDelayed(new Runnable() {
            @Override
            public void run() {
                smoothScrollBy(1000, 0);
            }
        }, 5);
    }
 
开发者ID:weimin96,项目名称:shareNote,代码行数:16,代码来源:TabIconView.java

示例5: getView

import android.widget.ImageButton; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (LayoutParams.MATCH_PARENT != mWidth) {
        mKeyWidth = (mWidth - 2 * mMarginCol - mPaddingLeft
                - mPaddingRight) / 3;
    }
    mKeyHeight = (mHeight - mTitleHeight - mPaddingTop - mPaddingBottom
            - 3 * mMarginRow) / 4;
    ImageButton buttonView = new ImageButton(mContext);
    buttonView.setScaleType(ScaleType.CENTER_INSIDE);
    buttonView.setLayoutParams(
            new AbsListView.LayoutParams(mKeyWidth, mKeyHeight));

    TextView textView = new TextView(mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        textView.setTextColor(
                mContext.getResources().getColor(mNumColor));
    } else {
        textView.setTextColor(mNumColor);
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNumSize);
    textView.setGravity(Gravity.CENTER);
    textView.setLayoutParams(
            new AbsListView.LayoutParams(mKeyWidth, mKeyHeight));
    if (!mIsAudio) {
        buttonView.setSoundEffectsEnabled(false);
        textView.setSoundEffectsEnabled(false);
    }

    long id = getItemId(position);
    String key = (String) getItem(position);
    if (Constant.CONFIRM_BUTTON_ITEM_ID == id) {
        if (null != mDoneForeSelector && null != mDoneBgSelector) {
            setDoneKey(buttonView);
        } else {
            setDefaultDoneDelKey(textView);
            String doneKeyStr = mContext.getResources()
                    .getString(R.string.str_done);
            textView.setText(doneKeyStr);
            int doneKeyColor = mContext.getResources()
                    .getColor(R.color.btn_security_keyboard_done);

            textView.setTextColor(doneKeyColor);
            int doneBackGroundColor = mContext.getResources()
                    .getColor(R.color.bg_security_keyboard_title);
            textView.setBackgroundColor(doneBackGroundColor);
            textView.setTextSize(16);
            textView.setId((int) getItemId(position));
            textView.setOnClickListener(onPasswordButtonClickListener);
            return textView;
        }
    } else if (Constant.DELETE_BUTTON_ITEM_ID == id) {
        if (null != mDelForeSelector || null != mDelBgSelector) {
            setDelKey(buttonView);
        } else {
            textView.setText(key);
            setDefaultDoneDelKey(textView);
            textView.setId((int) getItemId(position));
            textView.setOnClickListener(onPasswordButtonClickListener);
            return textView;
        }
    } else {
        if (null != mNumForeSelectorArray) {
            setNumberKey(buttonView, (int) id);
        } else {
            setDefaultNumKey(textView, (int) id);
            textView.setId((int) getItemId(position));
            textView.setOnClickListener(onPasswordButtonClickListener);
            return textView;
        }
    }
    buttonView.setId((int) getItemId(position));
    buttonView.setOnClickListener(onPasswordButtonClickListener);
    return buttonView;
}
 
开发者ID:VigorousLiang,项目名称:PWEditText-SafeKeyboard,代码行数:77,代码来源:SafetyKeyboard.java

示例6: initMainLeftViews

import android.widget.ImageButton; //导入方法依赖的package包/类
/**
 * 初始化主视图左边部分
 *
 * @param context
 */
private void initMainLeftViews(Context context) {
    LayoutParams leftInnerParams = new LayoutParams(WRAP_CONTENT, MATCH_PARENT);
    leftInnerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    leftInnerParams.addRule(RelativeLayout.CENTER_VERTICAL);

    if (leftType == TYPE_LEFT_TEXTVIEW) {
        // 初始化左边TextView
        tvLeft = new TextView(context);
        tvLeft.setId(ViewFinder.generateViewId());
        tvLeft.setText(leftText);
        tvLeft.setTextColor(leftTextColor);
        tvLeft.setTextSize(TypedValue.COMPLEX_UNIT_PX, leftTextSize);
        tvLeft.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        tvLeft.setSingleLine(true);
        tvLeft.setOnClickListener(this);
        // 设置DrawableLeft及DrawablePadding
        if (leftDrawable != 0) {
            tvLeft.setCompoundDrawablePadding((int) leftDrawablePadding);
            if (SysUtils.hasJellyBeanMr1()) {
                tvLeft.setCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, 0, 0, 0);
            } else {
                tvLeft.setCompoundDrawablesWithIntrinsicBounds(leftDrawable, 0, 0, 0);
            }
            tvLeft.setPadding(0, 0, PADDING_5, 0);
        } else {
            tvLeft.setPadding(PADDING_5, 0, PADDING_5, 0);
        }

        rlMain.addView(tvLeft, leftInnerParams);
        mFadeViewList.add(tvLeft);
    } else if (leftType == TYPE_LEFT_IMAGEBUTTON) {
        // 初始化左边ImageButton
        btnLeft = new ImageButton(context);
        btnLeft.setId(ViewFinder.generateViewId());
        btnLeft.setBackgroundColor(Color.TRANSPARENT);
        btnLeft.setImageResource(leftImageResource);
        btnLeft.setPadding(PADDING_12, 0, PADDING_12, 0);
        btnLeft.setOnClickListener(this);

        rlMain.addView(btnLeft, leftInnerParams);
        mFadeViewList.add(btnLeft);
    } else if (leftType == TYPE_LEFT_CUSTOM_VIEW) {
        // 初始化自定义View
        viewCustomLeft = LayoutInflater.from(context).inflate(leftCustomViewRes, null);
        if (viewCustomLeft.getId() == 0) {
            viewCustomLeft.setId(ViewFinder.generateViewId());
        }
        rlMain.addView(viewCustomLeft, leftInnerParams);
        mFadeViewList.add(viewCustomLeft);
    }
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:57,代码来源:CommonTitleBar.java

示例7: initMainRightViews

import android.widget.ImageButton; //导入方法依赖的package包/类
/**
 * 初始化主视图右边部分
 *
 * @param context
 */
private void initMainRightViews(Context context) {
    LayoutParams rightInnerParams = new LayoutParams(WRAP_CONTENT, MATCH_PARENT);
    rightInnerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    rightInnerParams.addRule(RelativeLayout.CENTER_VERTICAL);

    if (rightType == TYPE_RIGHT_TEXTVIEW) {
        // 初始化右边TextView
        tvRight = new TextView(context);
        tvRight.setId(ViewFinder.generateViewId());
        tvRight.setText(rightText);
        tvRight.setTextColor(rightTextColor);
        tvRight.setTextSize(TypedValue.COMPLEX_UNIT_PX, rightTextSize);
        tvRight.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        tvRight.setSingleLine(true);
        tvRight.setPadding(PADDING_15, 0, PADDING_15, 0);
        tvRight.setOnClickListener(this);
        rlMain.addView(tvRight, rightInnerParams);
        mFadeViewList.add(tvRight);
    } else if (rightType == TYPE_RIGHT_IMAGEBUTTON) {
        // 初始化右边ImageBtn
        btnRight = new ImageButton(context);
        btnRight.setId(ViewFinder.generateViewId());
        btnRight.setImageResource(rightImageResource);
        btnRight.setBackgroundColor(Color.TRANSPARENT);
        btnRight.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        btnRight.setPadding(PADDING_15, 0, PADDING_15, 0);
        btnRight.setOnClickListener(this);
        rlMain.addView(btnRight, rightInnerParams);
        mFadeViewList.add(btnRight);
    } else if (rightType == TYPE_RIGHT_CUSTOM_VIEW) {
        // 初始化自定义view
        viewCustomRight = LayoutInflater.from(context).inflate(rightCustomViewRes, null);
        if (viewCustomRight.getId() == 0) {
            viewCustomRight.setId(ViewFinder.generateViewId());
        }
        rlMain.addView(viewCustomRight, rightInnerParams);

        mFadeViewList.add(viewCustomRight);
    }
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:46,代码来源:CommonTitleBar.java


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