package com.example.popcorn.interfaceswithjava; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.RelativeLayout; import android.widget.Button; import android.graphics.Color; import android.widget.EditText; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //declaring objects RelativeLayout kardosLayout = new RelativeLayout(this); Button kardosButton = new Button(this); EditText kardosText = new EditText(this); //giving Id's kardosButton.setId(1); kardosText.setId(2); //container RelativeLayout.LayoutParams LayoutPosition = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT ); //position LayoutPosition.addRule(RelativeLayout.CENTER_HORIZONTAL); LayoutPosition.addRule(RelativeLayout.CENTER_VERTICAL); //color kardosLayout.setBackgroundColor(Color.YELLOW); kardosButton.setBackgroundColor(Color.BLACK); //button kardosButton.setTextColor(Color.WHITE); kardosButton.setText("hi there why dont you click me :)"); //adding the button to the layout (button is now child of layout) kardosLayout.addView(kardosButton, LayoutPosition); //viewing the layout setContentView(kardosLayout); } }