System.out.println("Clicked " + nClicks + " times."); }); button.setPadding(new Insets(10)); button.setPrefWidth(100);
int buttonX = 50; // Arbitrary values - use whatever you want int buttonY = 100; Button newButton = new Button(); newButton.setPadding(buttonX, buttonY, 0, 0); // Other button setup
int buttonX = 50; // Arbitrary values - use whatever you want int buttonY = 100; int viewX = myView.getLeft(); int viewY = myView.getTop(); Button newButton = new Button(); newButton.setPadding(buttonX - viewX, buttonY - viewY, 0, 0); // Other button setup
for padding Button btn = new Button(MainView.this); btn.setText("Button"); btn.setPadding(10, 10, 10, 10); mylist .addFooterView(addToFav);
LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); Button okButton=new Button(this); okButton.setText("some text"); Random r = new Random(); okButton.setPadding(r.nextInt(), r.nextInt(), r.nextInt(), r.nextInt()) ll.addView(okButton, layoutParams);
Button note_chart_btn; note_chart_btn = new Button(ctx); note_chart_btn.setText(txt); note_chart_btn.setGravity(Gravity.CENTER); note_chart_btn.setPadding(left, top, right, bottom);
Button btn = new Button(); btn.setGraphic(new ImageView("image")); btn.setPadding(Insets.EMPTY);
Button btn = new Button("Say 'Hello World'"); // circular shape scaled to Button dimensions = ellipse btn.setShape(new Circle(1)); // increase distance from edges to text btn.setPadding(new Insets(8));
LinearLayout ly = (LinearLayout) findViewById(R.id.verify); Button buyButton = new Button(this); buyButton.setText("button"); buyButton.setLayoutParams(new LayoutParams(50, 50)); buyButton.setPadding(10, 10, 10, 10); ly.addView(buyButton);
for (int i = 0; i < count; i++) { // creates button final Button btn = new Button(this); btn.setLayoutParams(new ViewGroup.LayoutParams( 250,150)); btn.setPadding(0, 8, 0, 8); //or set margin if u need btn.setTag(i); yourContainserView.addView(channelBtn, i); }
SingleTouchEventView view = new SingleTouchEventView(this, null); Button btn = new Button(this); LayoutParams pars = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); btn.setLayoutParams(pars); btn.setText("Hello World"); btn.setPadding(10, 10, 10, 10); view.addView(btn); setContentView(view);
public void applyTextOffset(Button button, int buttonWidth, int image) { int textWidth = (int) button.getPaint().measureText( button.getText().toString()); int padding = (buttonWidth / 2) - ((textWidth / 2) + ((BitmapDrawable) this.getResources().getDrawable(image)).getBitmap().getWidth()); button.setPadding(padding, 0, 0, 0); button.setCompoundDrawablePadding(-padding); }
Button myButton = new Button(/* your context, probably "this" */); myButton.setLayoutParams( new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); myButton.setPadding(0, 32, 0, 0); myButton.setText("this is a test"); myButton.setTextColor(android.R.color.black); myButton.setBackgroundResource(R.id.ic_launcher);
private Button createButton(String number) { Button button = new Button(this); button.setText(number); button.setPadding(5, 0, 5, 0); button.setTextSize(14f); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(WRAP_CONTENT, convertToPixel(40)); layoutParams.setMargins(convertToPixel(10), convertToPixel(10), 0, 0); button.setLayoutParams(layoutParams); return button; } private int convertToPixel(int n) { Resources r = getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, n, r.getDisplayMetrics()); return (int) px; }
GridLayout.LayoutParams lp = new GridLayout.LayoutParams(); lp.setMargins(0, 0, 0, 0); lp.rowSpec = GridLayout.spec(row); lp.columnSpec = GridLayout.spec(col); //lp.width = 40; //lp.height = 40; Button b = new Button(this); //b.setWidth(40); //b.setHeight(40); b.setText(Integer.toString(r.nextInt(10))); b.setPadding(0, 0, 0, 0); b.setLayoutParams(lp); v.addView(b, lp); }
@Override public View getView(int position, View convertView, ViewGroup parent) { Button btn; if(convertView == null){ btn = new Button(context); btn.setPadding(3,3,3,3); }else{ btn = (Button)convertView; } btn.setText(getItem(position)); btn.setTextColor(Color.WHITE); btn.setBackgroundResource(R.drawable.gridbuttonshape); //btn.setTag("btn_"+getItem(position)); btn.setTag(getItem(position)); btn.setOnClickListener(clickListener); return btn; }
for (int i = 0; i < ch.length; i++) { Button button = new Button(this); button.setTextColor(context.getResources().getColor(R.color.black)); button.setPadding(5, 5, 5, 5); if (Integer.parseInt(String.valueOf(ch[i])) == 0) { button.setText("No"); button.setId(2000 + 0); layout.addView(button, layoutParams); button.setOnClickListener(this); } if (Integer.parseInt(String.valueOf(ch[i])) == 1) { button.setText("Less"); button.setId(2000 + 1); layout.addView(button, layoutParams); button.setOnClickListener(this); } if (Integer.parseInt(String.valueOf(ch[i])) == 2) { button.setText("Half"); button.setId(2000 + 2); layout.addView(button, layoutParams); button.setOnClickListener(this); } }
GridLayout buttonLayout = new GridLayout(this); buttonLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); buttonLayout.setOrientation(GridLayout.HORIZONTAL); buttonLayout.setColumnCount(3); //Amount of colums for(int i = 0; i < numberOfButtons; i++) { Button b = new Button(this); b.setText(i); b.setPadding(5,5,5,5); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { //Do Something on click } buttonLayout.addView(b); }
AbsoluteLayout al = new AbsoluteLayout(this); Button t = new Button(this); t.setHeight(300); t.setWidth(300); t.setText("TEST123"); t.setPadding(120,120,0,0); setContentView(al);
Button btn = new Button(); btn.setGraphic(new ImageView(image)); btn.setPadding(new Insets(-1,-1,-1,-1)); btn.setOnAction(new EventHandler<ActionEvent>() {