android.widget.Button.setId()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(293)

本文整理了Java中android.widget.Button.setId()方法的一些代码示例,展示了Button.setId()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Button.setId()方法的具体详情如下:
包路径:android.widget.Button
类名称:Button
方法名:setId

Button.setId介绍

暂无

代码示例

代码示例来源:origin: derry/delion

private void prepareButtons() {
  mDoneButton = (Button) mLayout.findViewById(R.id.button_primary);
  mDoneButton.setId(R.id.payments_edit_done_button);
  mDoneButton.setOnClickListener(this);
  Button cancelButton = (Button) mLayout.findViewById(R.id.button_secondary);
  cancelButton.setId(R.id.payments_edit_cancel_button);
  cancelButton.setOnClickListener(this);
  DualControlLayout buttonBar = (DualControlLayout) mLayout.findViewById(R.id.button_bar);
  buttonBar.setAlignment(DualControlLayout.ALIGN_END);
}

代码示例来源:origin: trezor/trezor-android

btn.setText(mNegativeButtonText);
btn.setOnClickListener(mNegativeButtonListener);
btn.setId(android.R.id.button2);
if (mButtonsMatchWidth)
  ((LinearLayout.LayoutParams)btn.getLayoutParams()).weight = 1;
btn.setText(mNeutralButtonText);
btn.setOnClickListener(mNeutralButtonListener);
btn.setId(android.R.id.button3);
if (mButtonsMatchWidth)
  ((LinearLayout.LayoutParams)btn.getLayoutParams()).weight = 1;
vPositiveButton.setText(mPositiveButtonText);
vPositiveButton.setOnClickListener(mPositiveButtonListener);
vPositiveButton.setId(android.R.id.button1);
if (mButtonsMatchWidth)
  ((LinearLayout.LayoutParams)vPositiveButton.getLayoutParams()).weight = 1;

代码示例来源:origin: derry/delion

/**
 * Creates a standardized Button that can be used for DualControlLayouts showing buttons.
 *
 * @param isPrimary Whether or not the button is meant to act as a "Confirm" button.
 * @param text      Text to display on the button.
 * @param listener  Listener to alert when the button has been clicked.
 * @return Button that can be used in the view.
 */
public static Button createButtonForLayout(
    Context context, boolean isPrimary, String text, OnClickListener listener) {
  int lightActiveColor =
      ApiCompatibilityUtils.getColor(context.getResources(), R.color.light_active_color);
  if (isPrimary) {
    ButtonCompat primaryButton = new ButtonCompat(context, lightActiveColor, false);
    primaryButton.setId(R.id.button_primary);
    primaryButton.setOnClickListener(listener);
    primaryButton.setText(text);
    primaryButton.setTextColor(Color.WHITE);
    return primaryButton;
  } else {
    Button secondaryButton = ButtonCompat.createBorderlessButton(context);
    secondaryButton.setId(R.id.button_secondary);
    secondaryButton.setOnClickListener(listener);
    secondaryButton.setText(text);
    secondaryButton.setTextColor(lightActiveColor);
    return secondaryButton;
  }
}

代码示例来源:origin: nenick/espresso-macchiato

private void givenButtonToStartNextPage() {
  Button button = new Button(activityTestRule.getActivity());
  button.setText(nextPageButtonText);
  button.setId(nextPageButtonId);
  addViewToLayout(button, BaseActivity.rootLayout);
  button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      Intent intent = new Intent(activityTestRule.getActivity(), LandscapeFixedActivity.class);
      activityTestRule.getActivity().startActivity(intent);
    }
  });
}

代码示例来源:origin: avluis/Hentoid

/**
 * Create the button for the given attribute
 *
 * @param attribute Attribute the button should represent
 * @param isSelected True if the button should appear as selected
 * @return Button representing the given Attribute, drawn as selected if needed
 */
private Button createTagSuggestionButton(Attribute attribute, boolean isSelected) {
  Button button = new Button(mContext);
  button.setText(MessageFormat.format("{0}({1})", attribute.getName(), attribute.getCount()));
  button.setBackgroundResource(R.drawable.btn_attribute_selector);
  button.setMinHeight(0);
  button.setMinimumHeight(0);
  colorButton(button, TAGFILTER_ACTIVE);
  button.setTag(attribute);
  button.setId(Math.abs(attribute.getId()));
  if (isSelected) button.setOnClickListener(v -> selectSearchTag(button));
  else button.setOnClickListener(v -> selectTagSuggestion(button));
  return button;
}

代码示例来源:origin: totond/YMenuView

private void setMenuButton() {
    mYMenuButton = new Button(mContext);
    //生成ID
    mYMenuButton.setId(generateViewId());
    //调用抽象方法来确定MenuButton的位置
    setMenuPosition(mYMenuButton);
//        mSetting.setMenuPosition(mYMenuButton);

    //设置打开关闭事件
    mYMenuButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        if (!isShowMenu) {
          showMenu();
        } else {
          closeMenu();
        }
      }
    });
    mYMenuButton.setBackgroundResource(mMenuButtonBackGroundId);

    addView(mYMenuButton);
  }

代码示例来源:origin: huangweicai/OkLibDemo

private void setMenuButton() {
    mYMenuButton = new Button(mContext);
    //生成ID
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      mYMenuButton.setId(generateViewId());
    }
    //调用抽象方法来确定MenuButton的位置
    setMenuPosition(mYMenuButton);
//        mSetting.setMenuPosition(mYMenuButton);

    //设置打开关闭事件
    mYMenuButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        if (!isShowMenu) {
          showMenu();
        } else {
          closeMenu();
        }
      }
    });
    mYMenuButton.setBackgroundResource(mMenuButtonBackGroundId);

    addView(mYMenuButton);
  }

代码示例来源:origin: AriesHoo/UIWidget

btn = (Button) View.inflate(mContext, R.layout.layout_alert_button_border_less, null);
btn.setId(witch == DialogInterface.BUTTON_NEGATIVE ?
    R.id.btn_negativeAlertDialog : witch == DialogInterface.BUTTON_NEUTRAL ?
    R.id.btn_neutralAlertDialog : R.id.btn_positiveAlertDialog);

代码示例来源:origin: nenick/espresso-macchiato

private void givenClickableView() {
  view = new Button(activityTestRule.getActivity());
  view.setId(viewId);
  addViewToLayout(view, BaseActivity.rootLayout);
  view.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      messageView.setText(VIEW_WAS_CLICKED_MESSAGE);
    }
  });
}

代码示例来源:origin: GeoODK/collect

mLaunchIntentButton.setId(QuestionWidget.newUniqueId());
mLaunchIntentButton.setText(buttonText);
mLaunchIntentButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);

代码示例来源:origin: GeoODK/collect

mDrawButton.setId(QuestionWidget.newUniqueId());
mDrawButton.setText(getContext().getString(R.string.draw_image));
mDrawButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);

代码示例来源:origin: vanniktech/RxPermission

camera.setId(VIEW_ID_CAMERA);
camera.setOnClickListener(new View.OnClickListener() {
 @Override public void onClick(final View v) {
location.setId(VIEW_ID_LOCATION);
location.setOnClickListener(new View.OnClickListener() {
 @Override public void onClick(final View v) {
write.setId(VIEW_ID_WRITE);
write.setOnClickListener(new View.OnClickListener() {
 @Override public void onClick(final View v) {

代码示例来源:origin: GeoODK/collect

mGetBarcodeButton.setId(QuestionWidget.newUniqueId());
mGetBarcodeButton.setText(getContext().getString(R.string.get_barcode));
mGetBarcodeButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP,

代码示例来源:origin: GeoODK/collect

mOpenUrlButton.setId(QuestionWidget.newUniqueId());
mOpenUrlButton.setText(getContext().getString(R.string.open_url));
mOpenUrlButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP,

代码示例来源:origin: nenick/espresso-macchiato

@Before
public void setup() {
  Button button = new Button(activityTestRule.getActivity());
  button.setId(buttonId);
  button.setText(buttonText);
  addViewToLayout(button, BaseActivity.rootLayout);
}

代码示例来源:origin: GeoODK/collect

mGetBearingButton.setId(QuestionWidget.newUniqueId());
mGetBearingButton.setPadding(20, 20, 20, 20);
mGetBearingButton.setText(getContext()

代码示例来源:origin: GeoODK/collect

mAnswerDisplay.setGravity(Gravity.CENTER);
createTraceButton = new Button(getContext());
createTraceButton.setId(QuestionWidget.newUniqueId());
createTraceButton.setText(getContext().getString(R.string.record_trace));
createTraceButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);

代码示例来源:origin: GeoODK/collect

createShapeButton.setId(QuestionWidget.newUniqueId());
createShapeButton.setText(getContext().getString(R.string.record_geoshape));
createShapeButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);

代码示例来源:origin: nenick/espresso-macchiato

private void givenDoubleClickableView() {
  view = new Button(activityTestRule.getActivity());
  view.setId(viewId);
  addViewToLayout(view, BaseActivity.rootLayout);

代码示例来源:origin: nenick/espresso-macchiato

private void givenViewLargerThanScreen() {
  ScrollView scrollView = new ScrollView(getActivity());
  scrollView.setId(android.R.id.candidatesArea);
  addViewToLayout(scrollView, BaseActivity.rootLayout);
  view = new Button(activityTestRule.getActivity());
  view.setHeight(3000);
  view.setWidth(2000);
  view.setId(viewId);
  addViewToLayout(view, android.R.id.candidatesArea);
}

相关文章

Button类方法