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


Java Button.setId方法代码示例

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


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

示例1: verifyContentViewBinding

import android.widget.Button; //导入方法依赖的package包/类
@Test
public void verifyContentViewBinding() {
  FrameLayout frameLayout = new FrameLayout(RuntimeEnvironment.application);
  Button button1 = new Button(RuntimeEnvironment.application);
  button1.setId(android.R.id.button1);
  frameLayout.addView(button1);
  Button button2 = new Button(RuntimeEnvironment.application);
  button2.setId(android.R.id.button2);
  frameLayout.addView(button2);
  Button button3 = new Button(RuntimeEnvironment.application);
  button3.setId(android.R.id.button3);
  frameLayout.addView(button3);
  View content = new View(RuntimeEnvironment.application);
  content.setId(android.R.id.content);
  frameLayout.addView(content);
  H h = new H(frameLayout);

  Unbinder unbinder = ButterKnife.bind(h, frameLayout);
  verifyHBound(h);
  unbinder.unbind();
  verifyHUnbound(h);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:UnbinderTest.java

示例2: createButtonForLayout

import android.widget.Button; //导入方法依赖的package包/类
/**
 * 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;
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:30,代码来源:DualControlLayout.java

示例3: setMenuButton

import android.widget.Button; //导入方法依赖的package包/类
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);
    }
 
开发者ID:totond,项目名称:YMenuView,代码行数:24,代码来源:YMenu.java

示例4: createAndAddEditButton

import android.widget.Button; //导入方法依赖的package包/类
private Button createAndAddEditButton(ViewGroup parent) {
    Resources resources = parent.getResources();
    Button view = DualControlLayout.createButtonForLayout(
            parent.getContext(), true, resources.getString(R.string.select), this);
    view.setId(R.id.payments_section);

    LayoutParams params =
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(params, mLargeSpacing);
    parent.addView(view, params);
    return view;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:13,代码来源:PaymentRequestSection.java

示例5: prepareButtons

import android.widget.Button; //导入方法依赖的package包/类
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);
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:13,代码来源:EditorView.java

示例6: initialize

import android.widget.Button; //导入方法依赖的package包/类
public void initialize(Context context) {
    this.setBackgroundColor(Color.WHITE);

    final int width = 90;
    final int height = 90;
    final int margin = 13;
    final int length = PointPath.mPathColors.length;
    int left = 10;

    for (int i = 0; i < length; ++i) {
        int color = PointPath.mPathColors[i];

        ImageView imgBtn = new ImageView(context);
        if (CURRENT_TYPE == STROCK_TYPE) {
            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            paint.setColor(Color.RED);
            paint.setStrokeWidth(PointPath.mPenStrock[i]);
            canvas.drawLine(0, height, width, 0, paint);
            imgBtn.setImageBitmap(bitmap);
            imgBtn.setBackgroundColor(Color.WHITE);

        } else {
            imgBtn.setBackgroundColor(color);

        }


        imgBtn.setOnClickListener(m_clickListener);
        imgBtn.setTag(i);

        LayoutParams params = new LayoutParams(width, height);
        params.setMargins(left, 30, 0, 0);
        params.addRule(Gravity.CENTER_VERTICAL);
        left += (margin + width);

        this.addView(imgBtn, params);
    }


    // Cancel button.
    Button btnCancel = new Button(context);
    btnCancel.setText("cancel");
    btnCancel.setId(CANCEL_BUTTON_ID);
    btnCancel.setTextSize(8);
    btnCancel.setOnClickListener(m_clickListener);
    LayoutParams btnCancelparams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, height);
    btnCancelparams.addRule(Gravity.CENTER);
    left += 10;
    btnCancelparams.setMargins(left, 30, 0, 0);
    this.addView(btnCancel, btnCancelparams);
}
 
开发者ID:ShaunSheep,项目名称:ScaleSketchPadDemo,代码行数:54,代码来源:PenStrockAndColorSelect.java

示例7: create

import android.widget.Button; //导入方法依赖的package包/类
/**验证返回对话框布局*/
public static LinearLayout create(Context context) {
	SizeHelper.prepare(context);

	LinearLayout root = new LinearLayout(context);
	ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
	root.setLayoutParams(params);
	root.setOrientation(LinearLayout.VERTICAL);

	TextView dialogHint = new TextView(context);
	dialogHint.setId(ResHelper.getIdRes(context, "tv_dialog_hint"));
	LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	hintParams.topMargin = SizeHelper.fromPxWidth(32);
	hintParams.bottomMargin = SizeHelper.fromPxWidth(32);
	dialogHint.setLayoutParams(hintParams);
	dialogHint.setPadding(SizeHelper.fromPxWidth(18), 0, SizeHelper.fromPxWidth(18), 0);
	dialogHint.setLineSpacing(SizeHelper.fromPxWidth(8), 1);
	int resid = ResHelper.getStringRes(context, "smssdk_make_sure_mobile_detail");
	dialogHint.setText(resid);
	dialogHint.setTextColor(0xffffffff);
	dialogHint.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(26));
	dialogHint.setGravity(Gravity.CENTER);
	root.addView(dialogHint);

	View line = new View(context);
	LinearLayout.LayoutParams lineParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
			SizeHelper.fromPxWidth(1));
	line.setLayoutParams(lineParams);
	line.setBackgroundColor(0xff737373);
	root.addView(line);

	LinearLayout wrapper = new LinearLayout(context);
	LinearLayout.LayoutParams wrapperParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	wrapper.setLayoutParams(wrapperParams);


	Button ok = new Button(context);
	ok.setId(ResHelper.getIdRes(context, "btn_dialog_ok"));
	LinearLayout.LayoutParams okParams = new LinearLayout.LayoutParams(0,SizeHelper.fromPxWidth(78),1);
	okParams.leftMargin = SizeHelper.fromPxWidth(3);
	ok.setLayoutParams(okParams);
	resid = ResHelper.getBitmapRes(context, "smssdk_dialog_btn_back");
	ok.setBackgroundResource(resid);
	int padding = SizeHelper.fromPxWidth(8);
	ok.setPadding(padding, padding, padding, padding);
	resid = ResHelper.getStringRes(context, "smssdk_ok");
	ok.setText(resid);
	ok.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(22));
	ok.setTextColor(0xffffffff);
	wrapper.addView(ok);

	View line2 = new View(context);
	LinearLayout.LayoutParams line2Params = new LinearLayout.LayoutParams(SizeHelper.fromPxWidth(1),
			LinearLayout.LayoutParams.MATCH_PARENT);
	line2.setLayoutParams(line2Params);
	line2.setBackgroundColor(0xff737373);
	wrapper.addView(line2);

	Button cancel = new Button(context);
	cancel.setId(ResHelper.getIdRes(context, "btn_dialog_cancel"));
	LinearLayout.LayoutParams cancelParams = new LinearLayout.LayoutParams(0,SizeHelper.fromPxWidth(78),1);
	cancelParams.rightMargin = SizeHelper.fromPxWidth(3);
	cancel.setLayoutParams(cancelParams);
	resid = ResHelper.getBitmapRes(context, "smssdk_dialog_btn_back");
	cancel.setBackgroundResource(resid);
	cancel.setPadding(padding, padding, padding, padding);
	resid = ResHelper.getStringRes(context, "smssdk_cancel");
	cancel.setText(resid);
	cancel.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(22));
	cancel.setTextColor(0xffffffff);
	wrapper.addView(cancel);

	root.addView(wrapper);
	return root;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:78,代码来源:BackVerifyDialogLayout.java

示例8: create

import android.widget.Button; //导入方法依赖的package包/类
public static RelativeLayout create(Context context) {
	SizeHelper.prepare(context);

	RelativeLayout root = new RelativeLayout(context);
	root.setId(ResHelper.getIdRes(context, "rl_lv_item_bg"));
	AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT,
			SizeHelper.fromPxWidth(95));
	root.setLayoutParams(params);
	int padding = SizeHelper.fromPxWidth(14);
	root.setPadding(padding, padding, padding, padding);
	root.setGravity(Gravity.CENTER_VERTICAL);
	root.setBackgroundColor(0xffffffff);

	AsyncImageView contactImage = new AsyncImageView(context);
	contactImage.setId(ResHelper.getIdRes(context, "iv_contact"));
	RelativeLayout.LayoutParams contactImageParams = new RelativeLayout.LayoutParams(SizeHelper.fromPxWidth(64),
			SizeHelper.fromPxWidth(64));
	contactImageParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
	contactImage.setLayoutParams(contactImageParams);
	contactImage.setScaleType(ScaleType.FIT_CENTER);
	root.addView(contactImage);

	LinearLayout wrapper = new LinearLayout(context);
	RelativeLayout.LayoutParams wrapperParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
			RelativeLayout.LayoutParams.WRAP_CONTENT);
	wrapperParams.addRule(RelativeLayout.RIGHT_OF, ResHelper.getIdRes(context, "iv_contact"));
	wrapperParams.addRule(RelativeLayout.CENTER_VERTICAL);
	wrapperParams.leftMargin = SizeHelper.fromPxWidth(12);
	wrapper.setLayoutParams(wrapperParams);
	wrapper.setOrientation(LinearLayout.VERTICAL);
	root.addView(wrapper);

	TextView name = new TextView(context);
	name.setId(ResHelper.getIdRes(context, "tv_name"));
	LinearLayout.LayoutParams nameParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	name.setLayoutParams(nameParams);
	name.setTextColor(0xff333333);
	name.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(28));
	wrapper.addView(name);

	TextView contact = new TextView(context);
	contact.setId(ResHelper.getIdRes(context, "tv_contact"));
	LinearLayout.LayoutParams contactParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
			LinearLayout.LayoutParams.WRAP_CONTENT);
	contact.setLayoutParams(contactParams);
	contact.setTextColor(0xff999999);
	contact.setTextSize(TypedValue.COMPLEX_UNIT_PX,SizeHelper.fromPxWidth(22));
	wrapper.addView(contact);

	Button add = new Button(context);
	add.setId(ResHelper.getIdRes(context, "btn_add"));
	RelativeLayout.LayoutParams addParams = new RelativeLayout.LayoutParams(SizeHelper.fromPxWidth(92),
			SizeHelper.fromPxWidth(46));
	addParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	addParams.addRule(RelativeLayout.CENTER_VERTICAL);
	add.setLayoutParams(addParams);
	int resid = ResHelper.getStringRes(context, "smssdk_add_contact");
	add.setText(resid);
	add.setTextSize(TypedValue.COMPLEX_UNIT_PX, SizeHelper.fromPxWidth(22));
	add.setTextColor(0xff797979);
	//resid = R.getBitmapRes(context, "smssdk_corners_bg");
	add.setBackgroundDrawable(DrawableHelper.createCornerBg(context));
	add.setPadding(0, 0, 0, 0);
	root.addView(add);

	return root;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:69,代码来源:ContactsListviewItemLayout.java

示例9: init

import android.widget.Button; //导入方法依赖的package包/类
private void init(Context context, int style){
        mContentPadding = ThemeUtil.dpToPx(context, 24);
        mActionMinWidth = ThemeUtil.dpToPx(context, 64);
        mActionHeight = ThemeUtil.dpToPx(context, 36);
        mActionOuterHeight = ThemeUtil.dpToPx(context, 48);
        mActionPadding_h = ThemeUtil.dpToPx(context, 8);
        mActionPadding_w = ThemeUtil.dpToPx(context, 8);
        mActionOuterPadding = ThemeUtil.dpToPx(context, 8);
        mDialogHorizontalPadding = ThemeUtil.dpToPx(context, 40);
        mDialogVerticalPadding = ThemeUtil.dpToPx(context, 24);

        mCardView = new DialogCardView(context);
        mContainer = new ContainerFrameLayout(context);
        mTitle = new TextView(context);
        mPositiveAction = new Button(context);
        mNegativeAction = new Button(context);
        mNeutralAction = new Button(context);

        mCardView.setPreventCornerOverlap(false);
        mCardView.setUseCompatPadding(true);

        mTitle.setId(TITLE);
        mTitle.setGravity(Gravity.START);
//        mTitle.setPadding(mContentPadding, mContentPadding, mContentPadding, mContentPadding - mActionPadding);
        mTitle.setPadding(mContentPadding, mContentPadding, 0, mContentPadding /2);
        mPositiveAction.setId(ACTION_POSITIVE);
        mPositiveAction.setPadding(mActionPadding_w, mActionPadding_h, mActionPadding_w, mActionPadding_h);
        //设置背景
        mPositiveAction.setBackgroundResource(R.drawable.button_white_stroke_green);
        mNegativeAction.setId(ACTION_NEGATIVE);
        mNegativeAction.setPadding(mActionPadding_w, mActionPadding_h, mActionPadding_w, mActionPadding_h);
        mNegativeAction.setBackgroundResource(0);
        mNeutralAction.setId(ACTION_NEUTRAL);
        mNeutralAction.setPadding(mActionPadding_w, mActionPadding_h, mActionPadding_w, mActionPadding_h);
        mNeutralAction.setBackgroundResource(0);

        mContainer.addView(mCardView);
        mCardView.addView(mTitle);
        mCardView.addView(mPositiveAction);
        mCardView.addView(mNegativeAction);
        mCardView.addView(mNeutralAction);

        backgroundColor(ThemeUtil.windowBackground(context, 0xFFFFFFFF));
        elevation(ThemeUtil.dpToPx(context, 4));
        cornerRadius(ThemeUtil.dpToPx(context, 2));
        dimAmount(0.5f);
        layoutDirection(View.LAYOUT_DIRECTION_LOCALE);
        titleTextAppearance(R.style.TextAppearance_AppCompat_Title);
        actionTextAppearance(R.style.TextAppearance_AppCompat_Button);
        dividerColor(0x1E000000);
        dividerHeight(ThemeUtil.dpToPx(context, 1));

        cancelable(true);
        canceledOnTouchOutside(true);
        clearContent();
        onCreate();
        applyStyle(style);

        super.setContentView(mContainer);
    }
 
开发者ID:l465659833,项目名称:Bigbang,代码行数:61,代码来源:Dialog.java

示例10: run

import android.widget.Button; //导入方法依赖的package包/类
@Override
public void run() {
    pageContent = cr.return_url();
    String all_topics = "";
    String all_titles = "";
    try {
        if(pageContent.isEmpty()) {
            t.setVisibility(View.VISIBLE);
            t.setText("اتصال به اینترنت لازم است.");
        }
        else {
            t.setVisibility(View.INVISIBLE);
            Document doc = Jsoup.parse(pageContent);
            doc.select("td.tcr").remove();
            doc.select("a.item1").remove();
            Elements topics = doc.select("a[href]");
            for(Element topic : topics) {
                String extracted_topic = topic.attr("href");
                if(! extracted_topic.contains("viewtopic")) {
                    continue;
                }
                if(extracted_topic.contains("p=")) {
                    continue;
                }
                all_topics += (extracted_topic + "`");
                String extracted_title = topic.text();
                all_titles += (extracted_title + "`");
            }
            topics_array = all_topics.split("`");
            String titles_array[] = all_titles.split("`");
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.bottomMargin = 10;
            lp.topMargin = 10;
            for(int i=0; i<titles_array.length; i++) {
                Button b = new Button(ViewForumActivity.this);
                b.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
                b.setText(titles_array[i]);
                b.setOnClickListener(button_listener);
                b.setBackgroundResource(R.drawable.button_shape);
                b.getBackground().setAlpha(100);
                b.setId(i);
                ll.addView(b, lp);
            }
        }
    } catch (Exception e) {
        t.setVisibility(View.VISIBLE);
        t.setText("اشکالی در برنامه یا اتصال به اینترنت وجود دارد. برای تلاش مجدد لطفا بر روی این متن کلیک کنید.");
    }
}
 
开发者ID:m47h4r,项目名称:arch-users-forum,代码行数:50,代码来源:ViewForumActivity.java

示例11: run

import android.widget.Button; //导入方法依赖的package包/类
@Override
public void run() {
    pageContent = cr.return_url();
    String all_topics = "";
    String all_titles = "";
    try {
        if(pageContent.isEmpty()) {
            t.setVisibility(View.VISIBLE);
            t.setText("اتصال به اینترنت لازم است.");
        }
        else {
            t.setVisibility(View.INVISIBLE);
            Document doc = Jsoup.parse(pageContent);
            Elements topics = doc.select("a[href]");
            for(Element topic : topics) {
                String extracted_topic = topic.attr("href");
                if(! extracted_topic.contains("viewforum")) {
                    continue;
                }
                all_topics += (extracted_topic + "`");
                String extracted_title = topic.text();
                all_titles += (extracted_title + "`");
            }
            topics_array = all_topics.split("`");
            String titles_array[] = all_titles.split("`");
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            lp.bottomMargin = 10;
            lp.topMargin = 10;
            for(int i=0; i<titles_array.length; i++) {
                Button b = new Button(MainActivity.this);
                b.setTextDirection(View.TEXT_DIRECTION_ANY_RTL);
                b.setText(titles_array[i]);
                b.setOnClickListener(button_listener);
                b.setBackgroundResource(R.drawable.button_shape);
                b.getBackground().setAlpha(100);
                b.setId(i);
                ll.addView(b, lp);
            }
        }
    } catch (Exception e) {
        t.setVisibility(View.VISIBLE);
        t.setText("اشکالی در برنامه یا اتصال به اینترنت وجود دارد. برای تلاش مجدد لطفا بر روی این متن کلیک کنید.");
    }
}
 
开发者ID:m47h4r,项目名称:arch-users-forum,代码行数:45,代码来源:MainActivity.java


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