當前位置: 首頁>>代碼示例>>Java>>正文


Java Button.setGravity方法代碼示例

本文整理匯總了Java中android.widget.Button.setGravity方法的典型用法代碼示例。如果您正苦於以下問題:Java Button.setGravity方法的具體用法?Java Button.setGravity怎麽用?Java Button.setGravity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.widget.Button的用法示例。


在下文中一共展示了Button.setGravity方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setPositiveButton

import android.widget.Button; //導入方法依賴的package包/類
/**
        * set positive button
        *
        * @param text the name of button
        */
       public void setPositiveButton(String text, final View.OnClickListener listener)
{
           Button button = new Button(mContext);
           LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
	LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
           button.setLayoutParams(params);
           button.setBackgroundResource(R.drawable.material_card);
           button.setTextColor(Color.argb(255, 35, 159, 242));
           button.setText(text);
           button.setGravity(Gravity.CENTER);
           button.setTextSize(14);
           button.setPadding(dip2px(12), 0, dip2px(32), dip2px(BUTTON_BOTTOM));
           button.setOnClickListener(listener);
           mButtonLayout.addView(button);
       }
 
開發者ID:stytooldex,項目名稱:pius1,代碼行數:21,代碼來源:MaterialDialog.java

示例2: setNegativeButton

import android.widget.Button; //導入方法依賴的package包/類
/**
        * set negative button
        *
        * @param text the name of button
        */
       public void setNegativeButton(String text, final View.OnClickListener listener)
{
           Button button = new Button(mContext);
           LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
	LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
           button.setLayoutParams(params);
           button.setBackgroundResource(R.drawable.material_card);
           button.setText(text);
           button.setTextColor(Color.argb(222, 0, 0, 0));
           button.setTextSize(14);
           button.setGravity(Gravity.CENTER);
           button.setPadding(0, 0, 0, dip2px(8));
           button.setOnClickListener(listener);
           if (mButtonLayout.getChildCount() > 0)
    {
               params.setMargins(20, 0, 10, dip2px(BUTTON_BOTTOM));
               button.setLayoutParams(params);
               mButtonLayout.addView(button, 1);
           }
    else
    {
               button.setLayoutParams(params);
               mButtonLayout.addView(button);
           }
       }
 
開發者ID:stytooldex,項目名稱:pius1,代碼行數:31,代碼來源:MaterialDialog.java

示例3: generateTopBarTextButton

import android.widget.Button; //導入方法依賴的package包/類
/**
 * 生成一個文本按鈕,並設置文字
 *
 * @param text 按鈕的文字
 * @return
 */
private Button generateTopBarTextButton(String text) {
    Button button = new Button(getContext());
    button.setBackgroundResource(0);
    button.setMinWidth(0);
    button.setMinHeight(0);
    button.setMinimumWidth(0);
    button.setMinimumHeight(0);
    int paddingHorizontal = getTopBarTextBtnPaddingHorizontal();
    button.setPadding(paddingHorizontal, 0, paddingHorizontal, 0);
    button.setTextColor(QMUIResHelper.getAttrColorStateList(getContext(), R.attr.qmui_topbar_text_btn_color_state_list));
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_topbar_text_btn_text_size));
    button.setGravity(Gravity.CENTER);
    button.setText(text);
    return button;
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:22,代碼來源:QMUITopBar.java

示例4: getButton

import android.widget.Button; //導入方法依賴的package包/類
private Button getButton(String text, int position) {

        // 動態生成選擇按鈕
        final Button button = new Button(mContext);
        button.setText(text);
        button.setTag(position);
        button.setTextColor(mBuilder.getItemTextColor());
        button.setTextSize(mBuilder.getItemTextSize());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams
                .MATCH_PARENT, mBuilder.getItemHeight());
        button.setLayoutParams(lp);
        button.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
        button.setPadding(UiUtils.dp2px(mContext,10),0,UiUtils.dp2px(mContext,10),0);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {

                if (mBuilder.getOnItemListener() != null) {

                    selectPosition = Integer.parseInt(button.getTag().toString());
                    mBuilder.getOnItemListener().onItemClick(button, selectPosition);

                }
            }
        });

        return button;
    }
 
開發者ID:wp521,項目名稱:MyFire,代碼行數:30,代碼來源:MDSelectionDialog.java

示例5: addButton

import android.widget.Button; //導入方法依賴的package包/類
private void addButton(final DemoInfo leaf){
	Button btn = new Button(getActivity());
	btn.setText(leaf.name);
	btn.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
	btn.setBackgroundResource(R.drawable.sel_menu3);
	btn.setTextSize(15);
	btn.setPadding(20, 0, 20, 0);
	btn.setTextColor(Color.WHITE);
	btn.setAllCaps(false);


	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, Utils.dip2px(getActivity(), 40));
	lp.gravity = Gravity.CENTER;
	lp.topMargin = Utils.dip2px(getActivity(), 5);
	lp.bottomMargin = Utils.dip2px(getActivity(), 5);
	lp.leftMargin = Utils.dip2px(getActivity(), 5);
	lp.rightMargin = Utils.dip2px(getActivity(), 5);
	ll_root.addView(btn, lp);

	btn.setOnClickListener(new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			if(leaf.onClickListener == null){
				Toast.makeText(getActivity(), "sorry,此功能尚未實現", Toast.LENGTH_SHORT).show();
			}else{
				leaf.onClickListener.onClick(v);
			}
		}
	});

}
 
開發者ID:cowthan,項目名稱:ayo-menu,代碼行數:33,代碼來源:DemoMenuActivityAttacher.java

示例6: generateSpanActionButton

import android.widget.Button; //導入方法依賴的package包/類
/**
 * 生成適用於對話框的按鈕
 */
public static Button generateSpanActionButton(Context context, String text, int iconRes, boolean hasLeftMargin) {
	Button button = new Button(context);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
			ViewGroup.LayoutParams.WRAP_CONTENT,
			QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	if(hasLeftMargin){
		lp.leftMargin = QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_margin_left);
	}
	button.setLayoutParams(lp);
	button.setMinHeight(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	button.setMinWidth(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_min_width));
	button.setMinimumWidth(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_min_width));
	button.setMinimumHeight(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	button.setText(text);
	if (iconRes != 0) {
		Drawable drawable = context.getResources().getDrawable(iconRes);
		if (drawable != null) {
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
			button.setCompoundDrawables(drawable, null, null, null);
			button.setCompoundDrawablePadding(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_drawable_padding));
		}

	}
	button.setGravity(Gravity.CENTER);
	button.setClickable(true);
	button.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_text_size));
	button.setTextColor(QMUIResHelper.getAttrColorStateList(context, R.attr.qmui_dialog_action_text_color));
	button.setBackground(QMUIResHelper.getAttrDrawable(context, R.attr.qmui_dialog_action_btn_bg));
	final int paddingHor = QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_padding_horizontal);
	button.setPadding(paddingHor, 0, paddingHor, 0);
	return button;
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:36,代碼來源:QMUIDialogAction.java

示例7: addAButton

import android.widget.Button; //導入方法依賴的package包/類
private void addAButton(final String text) {
    int dimension = (int) PixelDipConverter.convertDpToPixel(50, getContext());
    //int padding = (int) PixelDipConverter.convertDpToPixel(10, getContext());
    final Button name = new Button(getContext());

    name.setLayoutParams(new LinearLayout.LayoutParams(dimension, dimension));


    name.setGravity(Gravity.CENTER);

    name.setText(text);
    name.setTextSize(15);
    name.setAllCaps(true);

    //name.setPadding(padding, padding, padding, padding);

    name.setClickable(true);

    name.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            iAccessoryView.onButtonAccessoryViewClicked(text);
        }
    });

    name.setBackgroundResource(outValue.resourceId);
    addView(name);
}
 
開發者ID:ujjwalagrawal17,項目名稱:CodeCompilerApp,代碼行數:29,代碼來源:AccessoryView.java

示例8: generateSpanActionButton

import android.widget.Button; //導入方法依賴的package包/類
/**
 * 生成適用於對話框的按鈕
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static Button generateSpanActionButton(Context context, String text, int iconRes, boolean hasLeftMargin) {
	Button button = new Button(context);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
			ViewGroup.LayoutParams.WRAP_CONTENT,
			QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	if(hasLeftMargin){
		lp.leftMargin = QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_margin_left);
	}
	button.setLayoutParams(lp);
	button.setMinHeight(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	button.setMinWidth(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_min_width));
	button.setMinimumWidth(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_min_width));
	button.setMinimumHeight(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	button.setText(text);
	if (iconRes != 0) {
		Drawable drawable = ContextCompat.getDrawable(context, iconRes);
		if (drawable != null) {
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
			button.setCompoundDrawables(drawable, null, null, null);
			button.setCompoundDrawablePadding(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_drawable_padding));
		}

	}
	button.setGravity(Gravity.CENTER);
	button.setClickable(true);
	button.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_text_size));
	button.setTextColor(QMUIResHelper.getAttrColorStateList(context, R.attr.qmui_dialog_action_text_color));
	button.setBackground(QMUIResHelper.getAttrDrawable(context, R.attr.qmui_dialog_action_btn_bg));
	final int paddingHor = QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_padding_horizontal);
	button.setPadding(paddingHor, 0, paddingHor, 0);
	return button;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:37,代碼來源:QMUIDialogAction.java

示例9: generateTopBarTextButton

import android.widget.Button; //導入方法依賴的package包/類
/**
 * 生成一個文本按鈕,並設置文字
 *
 * @param text 按鈕的文字
 * @return 返回生成的按鈕
 */
private Button generateTopBarTextButton(String text) {
    Button button = new Button(getContext());
    button.setBackgroundResource(0);
    button.setMinWidth(0);
    button.setMinHeight(0);
    button.setMinimumWidth(0);
    button.setMinimumHeight(0);
    button.setPadding(mTopBarTextBtnPaddingHor, 0, mTopBarTextBtnPaddingHor, 0);
    button.setTextColor(mTopBarTextBtnTextColor);
    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTopBarTextBtnTextSize);
    button.setGravity(Gravity.CENTER);
    button.setText(text);
    return button;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:21,代碼來源:QMUITopBar.java

示例10: addButton

import android.widget.Button; //導入方法依賴的package包/類
private void addButton(final Leaf leaf){
	Button btn = new Button(getActivity());
	btn.setText(leaf.name);
	btn.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
	btn.setBackgroundResource(R.drawable.sel_menu2);
	btn.setTextSize(15);
	btn.setPadding(20, 0, 20, 0);
	btn.setTextColor(Color.WHITE);
	btn.setAllCaps(false);


	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, Utils.dip2px(getActivity(), 40));
	lp.gravity = Gravity.CENTER;
	lp.topMargin = Utils.dip2px(getActivity(), 5);
	lp.bottomMargin = Utils.dip2px(getActivity(), 5);
	lp.leftMargin = Utils.dip2px(getActivity(), 5);
	lp.rightMargin = Utils.dip2px(getActivity(), 5);
	ll_root.addView(btn, lp);

	btn.setOnClickListener(new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			if(leaf.attacherClass != null){
				Master.startPage(getActivity(), leaf.attacherClass, null);
			}else if(leaf.activityClass != null){
				Intent intent = new Intent(getActivity(), leaf.activityClass);
				getActivity().startActivity(intent);
			}else{
				Toast.makeText(getActivity(), "sorry,此功能尚未實現", Toast.LENGTH_SHORT).show();
			}
		}
	});

	if(leaf.attacherClass == null && leaf.activityClass == null){

	}else{
		btn.setBackgroundResource(R.drawable.sel_menu3);
	}

}
 
開發者ID:cowthan,項目名稱:ayo-menu,代碼行數:42,代碼來源:MenuItemFragment.java

示例11: init

import android.widget.Button; //導入方法依賴的package包/類
private void init(String text, int iconRes) {
	LinearLayout.LayoutParams parentLp = new LinearLayout.LayoutParams(
			ViewGroup.LayoutParams.MATCH_PARENT,
			QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_action_block_btn_height));
	setLayoutParams(parentLp);
	setBackground(QMUIResHelper.getAttrDrawable(getContext(), R.attr.qmui_dialog_action_block_btn_bg));
	setPadding(
			QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_padding_horizontal),
			0,
			QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_padding_horizontal),
			0
	);

          mButton = new Button(getContext());
	mButton.setBackgroundResource(0);
	mButton.setPadding(0, 0, 0, 0);
	LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
	lp.gravity = Gravity.RIGHT;
	mButton.setLayoutParams(lp);
	mButton.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
	mButton.setText(text);
	if (iconRes != 0) {
		Drawable drawable = ContextCompat.getDrawable(getContext(), iconRes);
		if (drawable != null) {
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
			mButton.setCompoundDrawables(drawable, null, null, null);
			mButton.setCompoundDrawablePadding(QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_action_drawable_padding));
		}

	}
	mButton.setMinHeight(0);
	mButton.setMinWidth(0);
	mButton.setMinimumWidth(0);
	mButton.setMinimumHeight(0);
	mButton.setClickable(false);
	mButton.setDuplicateParentStateEnabled(true);
	mButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_action_button_text_size));
	mButton.setTextColor(QMUIResHelper.getAttrColorStateList(getContext(), R.attr.qmui_dialog_action_text_color));

	addView(mButton);
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:42,代碼來源:QMUIDialogAction.java

示例12: init

import android.widget.Button; //導入方法依賴的package包/類
private void init(String text, int iconRes) {
	LinearLayout.LayoutParams parentLp = new LinearLayout.LayoutParams(
			ViewGroup.LayoutParams.MATCH_PARENT,
			QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_action_block_btn_height));
	setLayoutParams(parentLp);
          QMUIViewHelper.setBackgroundKeepingPadding(this, QMUIResHelper.getAttrDrawable(getContext(), R.attr.qmui_dialog_action_block_btn_bg));
	setPadding(
			QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_padding_horizontal),
			0,
			QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_padding_horizontal),
			0
	);

          mButton = new Button(getContext());
	mButton.setBackgroundResource(0);
	mButton.setPadding(0, 0, 0, 0);
	LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
	lp.gravity = Gravity.RIGHT;
	mButton.setLayoutParams(lp);
	mButton.setGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
	mButton.setText(text);
	if (iconRes != 0) {
		Drawable drawable = ContextCompat.getDrawable(getContext(), iconRes);
		if (drawable != null) {
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
			mButton.setCompoundDrawables(drawable, null, null, null);
			mButton.setCompoundDrawablePadding(QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_action_drawable_padding));
		}

	}
	mButton.setMinHeight(0);
	mButton.setMinWidth(0);
	mButton.setMinimumWidth(0);
	mButton.setMinimumHeight(0);
	mButton.setClickable(false);
	mButton.setDuplicateParentStateEnabled(true);
	mButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(getContext(), R.attr.qmui_dialog_action_button_text_size));
	mButton.setTextColor(QMUIResHelper.getAttrColorStateList(getContext(), R.attr.qmui_dialog_action_text_color));

	addView(mButton);
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:42,代碼來源:QMUIDialogAction.java


注:本文中的android.widget.Button.setGravity方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。