Code example for Button

Methods: setBackgroundDrawablesetIdsetLayoutParamssetTextsetTextColorsetTextSize

0
    headerView.addView(textView);
  } 
 
  @SuppressWarnings("deprecation") 
  private void loadUpdateButton(RelativeLayout headerView, Context context) {
    Button button = new Button(context);
    button.setId(UPDATE_BUTTON_ID);
 
    int margin = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float)20.0, getResources().getDisplayMetrics());
    int width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float)120.0, getResources().getDisplayMetrics());
     
    LayoutParams params = new LayoutParams(width, LayoutParams.WRAP_CONTENT);
    params.setMargins(margin, margin, margin, margin);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, TRUE);
    params.addRule(RelativeLayout.BELOW, VERSION_LABEL_ID);
    button.setLayoutParams(params);
    button.setBackgroundDrawable(getButtonSelector());
    button.setText("Update");
    button.setTextColor(Color.WHITE);
    button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
     
    headerView.addView(button);
  } 
 
  private Drawable getButtonSelector() {
Stop searching for code, let great code find you!  Add Codota to your java IDE