To use a Click of a Button there is many way in andoid studo, Today we will learn the easiest method to add onClick on a Button.
Hi Friends, Welcome to Nulled Source Code – NSC Today, We will learn how to Add logo or change logo of our App. So let’s get started. Open your Android Studio And Select your project Which we have created in our previous Video. Also you can watch out our Below Video For How To.
In Ths Post We Will Learn Followings:
- Fist of all We will learn How to Change or Add Logo to Our App
- How to add the OnClick method to our Button
- How to Add A Toast Message to Our OnClick Of a Button.
- How to Show Snackbar on Button Click.
To change the logo go to
File Menu > New > Image Asset
select the path where is your image.

Then A New Window Will appeared First of All select the Logo then Adjust the Logo using Slider than Done. See Below Image For an Idea…

Now our app logo successfully added to our app.
To change the color of the Background just Add the below line of code in your main Layout. As shown in below example: android:background=”@color/colorAccent”
<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:background="@color/colorAccent" android:layout_height="match_parent" tools:context=".MainActivity"> // put your all buttons, imagevews etc here. </androidx.constraintlayout.widget.ConstraintLayout>
Now we will learn how to set onClick to a Button in Android Studio Latest Version
First, of Create a Button see below Example: Set the Button id as android:id=”@+id/myButton”
<Button android:id="@+id/myButton" android:layout_width="250dp" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:gravity="center" android:text="@string/app_name" android:textColor="#ffffff" android:textSize="30sp" android:textStyle="bold" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/textView"> </Button>
Than goto Main Activity.java And implements the OnClick Listner
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Than define the Variable:
private Button btn; Than initalze the button to its id in OnCreate Method using below line of code: btn = (Button) findViewById(R.id.myButton); btn.setOnClickListener(this);
Finally add the below line of code to above two lines code:
btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Welcome to my App", Toast.LENGTH_LONG).show(); } }); 
Now we Will Learn How to Show Toast Message on This Button Click:
Just Add the Below line of code in Your MainActivity.java in under button onClick Method
Toast.makeText(MainActivity.this, "Welcome to my App", Toast.LENGTH_LONG).show();
Now Final Code Will be Looks Like below code:
package com.nulledsourcecode.firstapp; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // myButton is the id of our button we have set it to in our layout file. btn = (Button) findViewById(R.id.myButton); btn.setOnClickListener(this); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "Welcome to my App", Toast.LENGTH_LONG).show(); } }); } @Override public void onClick(View view) { } }
Now We Will Learn How To Show a Snackbar on click of a Button in Android Studio.
Just Add the Below line of Code in onClck method of the button:
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), "Welcome To Nulled Source Code - NSC", Snackbar.LENGTH_LONG); snackbar.show();
Now We will learn many things in today’s post see you in next post take care.
The Source Code is Give Below Download Free Don’t Forget to Subscribe our Channel.