Greetings App

 OUTPUT : 



Resource Link: https://drive.google.com/drive/folders/1vp4TVMTACXblVQM-HGPc1UrqWZoAoRV6?usp=sharing

XML Code:

<EditText
        android:id="@+id/edittext"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="285dp"
        android:hint="Enter your name"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
 
  <Button
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="49dp"
        android:text="Say Hello!"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edittext" />
 
   <TextView
        android:textSize="28sp"
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="79dp"
        android:text="Welcome to Greetings App"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


Java Code:


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editText = findViewById(R.id.edittext);
        myBtn = findViewById(R.id.btn);
        title = findViewById(R.id.title);


        myBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String inputName = editText.getText().toString();

                Toast.makeText(MainActivity.this,
                        "Welcome "+inputName +" to our App",Toast.LENGTH_LONG).show();
            }
        });

    }



   

Comments

Popular posts from this blog

Widgets

List View : Planet Application

Recycler View: MarketApp