本文整理汇总了Java中android.widget.Button.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java Button.setBackground方法的具体用法?Java Button.setBackground怎么用?Java Button.setBackground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.Button
的用法示例。
在下文中一共展示了Button.setBackground方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: showButtonFeedback
import android.widget.Button; //导入方法依赖的package包/类
public void showButtonFeedback(Button button, Drawable pressed, Drawable normal){
button.setBackground(pressed);
final Button but = button;
final Drawable norm = normal;
final int delay = 1000;
new CountDownTimer(delay, delay) {
public void onTick(long millisUntilFinished) {/*ignore*/}
public void onFinish() {
but.setBackground(norm);
}
}.start();
}
示例2: 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;
}
示例3: onCreateView
import android.widget.Button; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_channel, container, false);
TabLayout tabStrip = view.findViewById(R.id.channelTabLayout);
tabStrip.setSelectedTabIndicatorColor(getColor(getContext(), R.color.tabText));
tabStrip.setTabTextColors(getColor(getContext(), R.color.tabText), getColor(getContext(), R.color.tabText));
tabStrip.setupWithViewPager((ViewPager)view.findViewById(R.id.pager));
final Button followButton = view.findViewById(R.id.followButton);
if(following)
followButton.setBackground(getDrawable(getContext(), R.drawable.ic_favorite_black_24dp));
followButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(following) {
unfollow();
followButton.setBackground(getDrawable(getContext(), R.drawable.ic_favorite_border_black_24dp));
} else {
follow();
followButton.setBackground(getDrawable(getContext(), R.drawable.ic_favorite_black_24dp));
}
}
});
return view;
}
示例4: setKeyColor
import android.widget.Button; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void setKeyColor(Button key, Drawable bg) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
key.setBackgroundDrawable(bg);
} else {
key.setBackground(bg);
}
}
示例5: viewForEmptyDataSet
import android.widget.Button; //导入方法依赖的package包/类
@Override
public Button viewForEmptyDataSet(RelativeLayout layout,PHEmptyDataSet.TapNoDataType type) {
Button btn = new Button(this);
btn.setLayoutParams(new ViewGroup.LayoutParams(200,200));
// Bitmap bitmap = BitmapFactory.decodeResource(res,R.drawable.m123);
Drawable draw = new BitmapDrawable(getResources(),BitmapFactory.decodeResource(getResources(),R.drawable.m123));
btn.setBackground(draw);
btn.setText("goog");
btn.setTextColor(Color.RED);
btn.setTextSize((float)8.0);
return btn;
}
示例6: setBarTheme
import android.widget.Button; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private static void setBarTheme(Activity activity, int theme) {
Button menuButton = (Button)activity.findViewById(R.id.menuButton);
Button searchButton = (Button)activity.findViewById(R.id.searchButton);
Button webSearchButton = (Button)activity.findViewById(R.id.webSearchButton);
EditText searchField = (EditText)activity.findViewById(R.id.textField);
Resources resources = activity.getResources();
switch (theme) {
case DEFAULT_THEME:
case LIGHT:
case WALLPAPER_LIGHT:
if (Build.VERSION.SDK_INT >= 16) {
menuButton.setBackground(resources.getDrawable(R.drawable.menu_bg));
searchButton.setBackground(resources.getDrawable(R.drawable.search_bg));
webSearchButton.setBackground(resources.getDrawable(R.drawable.web_search_bg));
} else {
menuButton.setBackgroundDrawable(resources.getDrawable(R.drawable.menu_bg));
searchButton.setBackgroundDrawable(resources.getDrawable(R.drawable.search_bg));
webSearchButton.setBackgroundDrawable(resources.getDrawable(R.drawable.web_search_bg));
}
searchField.setTextColor(Color.WHITE);
break;
default:
if (Build.VERSION.SDK_INT >= 16) {
menuButton.setBackground(resources.getDrawable(R.drawable.menu_dark_bg));
searchButton.setBackground(resources.getDrawable(R.drawable.search_dark_bg));
webSearchButton.setBackground(resources.getDrawable(R.drawable.web_search_dark_bg));
} else {
menuButton.setBackgroundDrawable(resources.getDrawable(R.drawable.menu_dark_bg));
searchButton.setBackgroundDrawable(resources.getDrawable(R.drawable.search_dark_bg));
webSearchButton.setBackgroundDrawable(resources.getDrawable(R.drawable.web_search_dark_bg));
}
searchField.setTextColor(Color.BLACK);
}
}
示例7: 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;
}