Creating Android Button programmatically

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:id="@+id/myLinear1">

</LinearLayout>

MainActivity.java

package com.mycompany.myapp;

import android.app.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import android.widget.*;

public class MainActivity extends Activity 
{
	LinearLayout myLinear1;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
		
		myLinear1 = findViewById(R.id.myLinear1);
		
		final Button mySubmit1 = new Button(MainActivity.this);
		mySubmit1.setHint("I was created dynamically");
		mySubmit1.setHintTextColor(Color.BLUE);
		mySubmit1.setTextSize(23);
		
		myLinear1.addView(mySubmit1);
    }
}