本文整理汇总了Java中android.widget.Button.setCompoundDrawablePadding方法的典型用法代码示例。如果您正苦于以下问题:Java Button.setCompoundDrawablePadding方法的具体用法?Java Button.setCompoundDrawablePadding怎么用?Java Button.setCompoundDrawablePadding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.Button
的用法示例。
在下文中一共展示了Button.setCompoundDrawablePadding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}