Create an application that designs a layout with a text box and button named submit. The user should enter the text in the text box. When the submit button is clicked than the text in the text box should be displyed in the toast, using Java in Android Studio.

 Java Code:-

public class MainActivity extends AppCompatActivity {

EditText txt;
Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt=findViewById(R.id.textView);
btn=findViewById(R.id.button);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),txt.getText().toString(),Toast.LENGTH_SHORT).show();
}
});
}
}




XML Code:-

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Submit"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="55dp"
android:layout_marginTop="213dp"
android:layout_marginEnd="55dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>