本文整理汇总了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;
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}