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


Java Button.setBackground方法代碼示例

本文整理匯總了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();
}
 
開發者ID:Captwalloper,項目名稱:NUI_Project,代碼行數:16,代碼來源:SongPlayerFragment.java

示例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;
}
 
開發者ID:coopese,項目名稱:qmui,代碼行數:36,代碼來源:QMUIDialogAction.java

示例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;
}
 
開發者ID:invghost,項目名稱:NeoStream,代碼行數:30,代碼來源:ChannelFragment.java

示例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);
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:10,代碼來源:Key.java

示例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;
    }
 
開發者ID:HeterPu,項目名稱:PHEmptyDataSetForAndroid,代碼行數:14,代碼來源:MainActivity.java

示例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);
	}
}
 
開發者ID:HenriDellal,項目名稱:emerald,代碼行數:36,代碼來源:Themer.java

示例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;
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:37,代碼來源:QMUIDialogAction.java


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