private Button createButton(int id, String text) {
   Button btn = new Button(this);
   btn.setId(id);
   btn.setText(text);
   btn.setMinWidth(dp2px(50));
   btn.setMaxWidth(dp2px(120));
   btn.setOnClickListener(this);
   return btn;
 }
Exemplo n.º 2
0
 private void lockButtonSizes(int NUM_ROWS, int NUM_COLS) {
   for (int row = 0; row != NUM_ROWS; row++) {
     for (int col = 0; col != NUM_COLS; col++) {
       Button button = buttons[row][col];
       int width = button.getWidth();
       button.setMinWidth(width);
       button.setMaxWidth(width);
       int height = button.getHeight();
       button.setMinHeight(height);
       button.setMaxHeight(height);
     }
   }
 }
  public Button createButton(CharSequence text, View.OnClickListener click) {

    float density = this.getContext().getResources().getDisplayMetrics().density;
    int button_height = (int) (36.0f * density);
    int button_margin = (int) (4.0f * density);
    int button_padding = (int) (8.0f * density);
    int min_width = (int) (64.0f * density);

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, button_height);
    params.setMargins(button_margin, 0, 0, 0);

    Button button = new Button(this.getContext());
    button.setLayoutParams(params);
    button.setPadding(button_padding, 0, button_padding, 0);
    button.setBackgroundResource(R.drawable.touch_holo_light_round_angle);
    button.setTextColor(this.getContext().getResources().getColor(R.color.blue));
    button.setTextSize(16);
    button.setMinWidth(min_width);
    button.setOnClickListener(new OnClick(this, click));
    button.setText(text);
    button.setTypeface(null, Typeface.BOLD);

    return button;
  }