Code example for Button

Methods: setGravitysetPaddingsetTextsetTextColorsetTextSize, setBackgroundDrawable, setId, setLayoutParams

0
    wrapperLayoutFeedback.addView(button);
  } 
 
  @SuppressWarnings("deprecation") 
  private void loadAddResponseButton(Context context) {
    Button button = new Button(context);
    button.setId(ADD_RESPONSE_BUTTON_ID);
   
    int paddingTopBottom = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 10.0, getResources().getDisplayMetrics());
    int margin = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 10.0, getResources().getDisplayMetrics());
    int marginRight = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) 5.0, getResources().getDisplayMetrics());
     
    android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
     
    params.setMargins(0, 0, marginRight, margin);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    params.weight = 1.0f;
     
    button.setLayoutParams(params);
    button.setBackgroundDrawable(getButtonSelector());
    button.setPadding(0, paddingTopBottom, 0, paddingTopBottom);
    button.setGravity(Gravity.CENTER);
    button.setText("Add a Response");
    button.setTextColor(Color.WHITE);
    button.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
     
    wrapperLayoutButtons.addView(button);
  } 
   
  @SuppressWarnings("deprecation")