Refine search
LinearLayout myLayout = findViewById(R.id.main); Button myButton = new Button(this); myButton.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); myLayout.addView(myButton);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.weight = 1.0f; Button button = new Button(this); button.setLayoutParams(params);
Button bt = new Button(this); bt.setText("A Button"); bt.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linerLayout.addView(bt);
LinearLayout layout = (LinearLayout) findViewById(R.id.linear_layout_tags); layout.setOrientation(LinearLayout.VERTICAL); //Can also be done in xml by android:orientation="vertical" for (int i = 0; i < 3; i++) { LinearLayout row = new LinearLayout(this); row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); for (int j = 0; j < 4; j++ { Button btnTag = new Button(this); btnTag.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); btnTag.setText("Button " + (j + 1 + (i * 4)); btnTag.setId(j + 1 + (i * 4)); row.addView(btnTag); } layout.addView(row); }
AlertDialog.Builder myDialog = new AlertDialog.Builder(Login.this); Button button = new Button(Login.this); EditText editText = new EditText(Login.this); TextView textView = new TextView(Login.this); button.setText("Send"); LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); buttonLayoutParams.setMargins(50, 10, 0, 0); button.setLayoutParams(buttonLayoutParams); String resetPassword = editText.getText().toString(); LinearLayout layout = new LinearLayout(Login.this); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(textView); layout.addView(editText); layout.addView(button); myDialog.setView(layout); myDialog.show();
Button b = new Button (this); LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER; // if you want it centered params.span = 1; b..setLayoutParams(params); b.setText(""+f+c); b.setTextSize(10.0f); b.setTextColor(Color.rgb( 100, 200, 200)); tr.addView(b);
Button button=new Button(getActivity()); LayoutParams params=new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); button.setLayoutParams(params); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.ALIGN_PARENT_TOP); button.setText("openDrawer"); root.addView(button);
//the layout on which you are working LinearLayout layout = (LinearLayout) findViewById(R.id.linear_layout_tags); //set the properties for button Button btnTag = new Button(this); btnTag.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); btnTag.setText("Button"); btnTag.setId(some_random_id); //add button to the layout layout.addView(btnTag);
btn_setDate.setLayoutParams(button_params); btn_setDate.setText("Set Date"); btn_setDate.setId(SET_DATE); btn_setDate.setOnClickListener(this); btn_setTime.setLayoutParams(button_params); btn_setTime.setText("Set Time"); btn_setTime.setId(SET_TIME); btn_setTime.setOnClickListener(this); linear_top.addView(btn_setDate); linear_top.addView(btn_setTime); btn_set.setLayoutParams(button_params); btn_set.setText("Set"); btn_set.setId(SET); btn_set.setOnClickListener(this); btn_cancel.setLayoutParams(button_params); btn_cancel.setText("Cancel"); btn_cancel.setId(CANCEL); btn_cancel.setOnClickListener(this); linear_bottom.addView(btn_set); linear_bottom.addView(btn_cancel);
Button myButton = new Button(this); myButton.setLayoutParams(params); LinearLayout container = (LinearLayout)findViewById(R.id.container); container.addView(myButton);
/* Find Tablelayout defined in main.xml */ TableLayout tl = (TableLayout) findViewById(R.id.SaleOrderLines); /* Create a new row to be added. */ TableRow tr = new TableRow(this); tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); /* Create a Button to be the row-content. */ Button b = new Button(this); b.setText("Dynamic Button"); b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); /* Add Button to row. */ tr.addView(b); /* Add row to TableLayout. */ //tr.setBackgroundResource(R.drawable.sf_gradient_03); tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
LinearLayout ll = (LinearLayout)findViewById(R.id.layout); Button btn = new Button(this); btn.setText("Manual Add"); btn.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); ll.addView(btn);
LinearLayout layout = (LinearLayout) findViewById(R.id.layout); Button button = new Button(getApplicationContext()); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); button.setText("New Button"); button.setLayoutParams(layoutParams); layout.addView(button);
LinearLayout container = (LinearLayout)findViewById(R.id.container); Button btn = new Button(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); btn.setLayoutParams(lp); container.addView(btn);
// first Button RelativeLayout rLayout = (RelativeLayout) findViewById(R.id.rlayout); RelativeLayout.LayoutParams lprams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); Button tv1 = new Button(this); tv1.setText("Hello"); tv1.setLayoutParams(lprams); tv1.setId(1); rLayout.addView(tv1); // second Button RelativeLayout.LayoutParams newParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); Button tv2 = new Button(this); tv1.setText("Hello2"); newParams.addRule(RelativeLayout.RIGHT_OF, 1); tv2.setLayoutParams(newParams); tv2.setId(2); rLayout.addView(tv2);
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = (LinearLayout) View.inflate(this, R.layout.songs_layout, null); Button myButton = new Button(this); myButton.setText("Change View"); myButton.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); layout.addView(myButton); setContentView(layout); }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_remove_contact); LinearLayout ll = (LinearLayout) findViewById(R.id.vertic); Button button = new Button(this.getApplicationContext()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.weight = 1; button.setText("MR. ABC"); button.setLayoutParams(params); ll.addView(button, params); }
LinearLayout container = (LinearLayout)findViewById(R.id.container); Button btn = new Button(this); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); btn.setLayoutParams(lp); container.addView(btn);
RelativeLayout rl = new RelativeLayout(this); LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); rl.setLayoutParams(params); Button button = new Button(this); button.setText("Previous"); LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); button.setLayoutParams(params1); rl.addView(button);
LinearLayout layout = (LinearLayout) findViewById(R.id.myLayout); Button fav_up_btn = new Button(this); fav_up_btn.setText(roomName); fav_up_btn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); layout.addView(fav_up_btn);