本文整理汇总了Java中android.widget.ImageButton.setContentDescription方法的典型用法代码示例。如果您正苦于以下问题:Java ImageButton.setContentDescription方法的具体用法?Java ImageButton.setContentDescription怎么用?Java ImageButton.setContentDescription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.ImageButton
的用法示例。
在下文中一共展示了ImageButton.setContentDescription方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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());
}
示例3: updateBottomBarButtons
import android.widget.ImageButton; //导入方法依赖的package包/类
/**
* Updates the custom buttons on bottom bar area.
* @param params The {@link CustomButtonParams} that describes the button to update.
*/
public void updateBottomBarButtons(CustomButtonParams params) {
ImageButton button = (ImageButton) getBottomBarView().findViewById(params.getId());
button.setContentDescription(params.getDescription());
button.setImageDrawable(params.getIcon(mActivity.getResources()));
}
示例4: addIconTab
import android.widget.ImageButton; //导入方法依赖的package包/类
private void addIconTab(final int position, int resId, String contentDescription) {
ImageButton tab = new ImageButton(getContext());
tab.setContentDescription(contentDescription);
tab.setImageResource(resId);
addTab(position, tab);
}