本文整理汇总了Java中android.widget.Button.setBackgroundResource方法的典型用法代码示例。如果您正苦于以下问题:Java Button.setBackgroundResource方法的具体用法?Java Button.setBackgroundResource怎么用?Java Button.setBackgroundResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.Button
的用法示例。
在下文中一共展示了Button.setBackgroundResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: addBtn
import android.widget.Button; //导入方法依赖的package包/类
public BottomPopMenu addBtn(String btnTxt, final int i){
Button button = new Button(mContext);
buttonMap.put(i, button);
button.setOnClickListener(v -> {
dismiss();
for (OnBtnClickListener btnClickListener : onBtnClickListener) {
btnClickListener.onBtnClick(i);
}
});
button.setBackgroundResource(R.drawable.umi_bg_corners_solid);
button.setLayoutParams(lp);
button.setText(btnTxt);
button.setTextColor(Color.WHITE);
btnLayout.addView(button);
return this;
}
示例3: onCreateView
import android.widget.Button; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_control_rule, container, false);
rulesRecyclerView = (ListView) view.findViewById(R.id.rulesRecyclerView);
iv_menu = (ImageView) view.findViewById(R.id.iv_menu);
iv_menu.setOnClickListener(this);
textTitle = (TextView) view.findViewById(R.id.tvTitle);
textTitle.setText(R.string.rule);
btn_add = (Button) view.findViewById(R.id.btn_add);
btn_add.setVisibility(View.VISIBLE);
// btn_add.setBackground(getContext().getDrawable(R.drawable.control_add));
btn_add.setBackgroundResource(R.drawable.control_add);
btn_add.setOnClickListener(this);
no_relativeLayout = (LinearLayout) view.findViewById(R.id.no_relativeLayout);
relativeLayout = (LinearLayout) view.findViewById(R.id.relativeLayout);
return view;
}
示例4: 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;
}
示例5: ViewHolder
import android.widget.Button; //导入方法依赖的package包/类
public ViewHolder(View itemView) {
super(itemView);
button = (Button) itemView.findViewById(R.id.collection_button);
button.setTextColor(ContextCompat.getColor(mActivity, R.color.colorBlack));
button.setBackgroundResource(R.drawable.ic_collection_button_black);
authorIcon = (CircleImageView) itemView.findViewById(R.id.author_icon);
authorName = (TextView) itemView.findViewById(R.id.author_name);
authorName.setTextColor(ContextCompat.getColor(mActivity, R.color.colorBlack));
authorName.setTypeface(Typeface.createFromAsset(mActivity.getAssets(), mActivity.getString(R.string.DB1FontPath)));
authorDescription = (TextView) itemView.findViewById(R.id.author_description);
authorDescription.setTextColor(ContextCompat.getColor(mActivity, R.color.colorBlack));
authorDescription.setTypeface(Typeface.createFromAsset(mActivity.getAssets(), mActivity.getString(R.string.LFontPath)));
clickLayout = (LinearLayout) itemView.findViewById(R.id.click_layout);
}
示例6: onBindViewHolder
import android.widget.Button; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, final OnRepeatListener onRepeatListener) {
Button btnRepeat = (Button) holder.itemView.findViewById(R.id.btnRepeat);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
btnRepeat.setBackgroundResource(R.drawable.no_pagination_button_ripple);
} else {
btnRepeat.setBackgroundResource(R.drawable.no_pagination_button_selector);
}
btnRepeat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onRepeatListener != null) {
onRepeatListener.onClickRepeat();
}
}
});
}
示例7: 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);
}
}
});
}
示例8: applyTheme
import android.widget.Button; //导入方法依赖的package包/类
private void applyTheme(View view) {
ArgusTheme theme = Argus.getInstance().getArgusTheme();
if(theme.getButtonDrawable() != 0) {
Button actionButton = (Button) view.findViewById(R.id.action_button);
if(actionButton != null) {
actionButton.setBackgroundResource(theme.getButtonDrawable());
}
}
}
示例9: show
import android.widget.Button; //导入方法依赖的package包/类
public void show() {
super.show();
int i = 0;
Button btn = null;
Iterator<Button> iterator = mButtons.iterator();
while (iterator.hasNext()) {
Button button = iterator.next();
if(button.getVisibility() != View.VISIBLE) {
continue;
}
++i;
btn = button;
}
if (i == 1) {
btn.setBackgroundResource(R.drawable.btn_dialog_single);
}
if (i == 2) {
btn.setSelected(true);
((ViewGroup.MarginLayoutParams)(this.mButtons.get(0)).getLayoutParams()).rightMargin = 1;
}
if (i == 3) {
btn.setSelected(true);
((ViewGroup.MarginLayoutParams)(this.mButtons.get(2)).getLayoutParams()).leftMargin = 1;
((ViewGroup.MarginLayoutParams)(this.mButtons.get(0)).getLayoutParams()).rightMargin = 1;
}
}
示例10: 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;
}
示例11: getView
import android.widget.Button; //导入方法依赖的package包/类
@Override
public View getView(final int i, final View view, ViewGroup viewGroup) {
final Button img = new Button(context);
int width = ScreenUtils.getScreenWidth(context) - DensityUtils.dp2px(context, 45);// 获取屏幕宽度
int height = 0;
width = width / 5;// 对当前的列数进行设置imgView的宽度
height = width * 5 / 6;
if (!weeklist[i]) {
img.setBackgroundResource(R.color.new_grty);
} else {
img.setBackgroundResource(R.color.colorPrimary);
}
img.setText(String.valueOf(i + 1));
img.setTextColor(Color.WHITE);
AbsListView.LayoutParams layout = new AbsListView.LayoutParams(width, height);
img.setLayoutParams(layout);
img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onItemClickListener != null) {
onItemClickListener.onItemClick(v, i, view.getId());
}
}
});
return img;
}
示例12: setButtonStatus
import android.widget.Button; //导入方法依赖的package包/类
private void setButtonStatus(Button button, boolean canClick) {
Logger.d(TAG, " setButtonStatus canClick : " + canClick);
if (canClick) {
button.setClickable(true);
button.setBackgroundResource(R.drawable.btn_blue_selecter);
button.setTextAppearance(this.mContext, R.style.letv_text_13_blue_white);
return;
}
button.setClickable(false);
button.setBackgroundResource(R.drawable.btn_grey);
button.setTextColor(Util.getContext().getResources().getColor(R.color.letv_color_ffa1a1a1));
}
示例13: setButtonStatus
import android.widget.Button; //导入方法依赖的package包/类
private void setButtonStatus(Button button, boolean canClick) {
LogInfo.log(TAG, " setButtonStatus canClick : " + canClick);
if (canClick) {
button.setClickable(true);
button.setBackgroundResource(2130837706);
button.setTextAppearance(this.mActivity, 2131230855);
return;
}
button.setClickable(false);
button.setBackgroundResource(2130837728);
button.setTextColor(getResources().getColor(2131493280));
}
示例14: 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;
}
示例15: 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);
}
}