Android

Add Two Number Program app in Android Studio

The App look Like This…

In this article i am gone to share how you can create android app which can add two numbers | you can check app screenshots which are given below

 

Add Two Number Program app
 

Activity_main.xml
Copy all this code and paste it

——————————————————————–

<?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"
    android:background="#FFFFFF"
    tools:context=".MainActivity">

<TextView
android:id=”@+id/textView5″
android:layout_width=”304dp”
android:layout_height=”91dp”
android:layout_marginTop=”55dp”
android:background=”#FFFFFF”
android:fontFamily=”sans-serif-light”
android:foregroundGravity=”center”
android:gravity=”center”
android:shadowColor=”#E91E63″
android:text=”@string/add_two_numbers”
android:textColor=”#E91E63″
android:textSize=”36sp”
android:textStyle=”bold”
app:flow_horizontalAlign=”center”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toTopOf=”parent” />

<EditText
android:id=”@+id/etNum2″
android:layout_width=”247dp”
android:layout_height=”66dp”
android:layout_marginTop=”48dp”
android:ems=”10″
android:gravity=”center”
android:hint=”Second Number”
android:inputType=”number”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toBottomOf=”@+id/etNum1″ />

<EditText
android:id=”@+id/etNum1″
android:layout_width=”247dp”
android:layout_height=”66dp”
android:layout_marginTop=”56dp”
android:ems=”10″
android:gravity=”center”
android:hint=”First Number”
android:inputType=”number”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintHorizontal_bias=”0.463″
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toBottomOf=”@+id/textView5″ />

<Button
android:id=”@+id/btnadd”
android:layout_width=”234dp”
android:layout_height=”65dp”
android:layout_marginTop=”48dp”
android:text=”Add”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toBottomOf=”@+id/etNum2″ />

<TextView
android:id=”@+id/tvanswer”
android:layout_width=”271dp”
android:layout_height=”82dp”
android:layout_marginTop=”172dp”
android:layout_marginBottom=”164dp”
android:gravity=”center”
android:text=”Answer”
android:textSize=”36sp”
app:layout_constraintBottom_toBottomOf=”parent”
app:layout_constraintEnd_toEndOf=”parent”
app:layout_constraintHorizontal_bias=”0.497″

app:layout_constraintStart_toStartOf=”parent”
app:layout_constraintTop_toBottomOf=”@+id/btnadd”
app:layout_constraintVertical_bias=”0.742″ />

</androidx.constraintlayout.widget.ConstraintLayout>


 

 

MainActivity.java
Copy all this code and paste it
——————————————————————–

package com.example.add;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
private EditText num1 ;
private EditText num2 ;
private Button add;
private TextView result;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

num1 = findViewById(R.id.etNum1);
num2 = findViewById(R.id.etNum2);
add = findViewById(R.id.btnadd);
result = findViewById(R.id.tvanswer);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

int number1 = Integer.parseInt(num1.getText().toString());
int number2 = Integer.parseInt(num2.getText().toString());
int sum = number1 + number2;
result.setText(“Answer is = “+ String.valueOf(sum));
}
});

}
}

 

 

 

string.xml
If you want to change app Name
——————————————————————–

 

<resources>
    <string name="app_name">Add Two Number</string>
    <string name="add_two_numbers">Add Two Numbers</string>
</resources>

How to Change app icon

1) First go to this website …
2) Generate your app icon & download zip file and Extract it…
3) Copy all ( mipmap name ) files and open android studio go to in your app res folder in the res folder you find 4 or 5 ( mipmap name files) replace all copy file with this files..

in short 

“in the res folder delete all mipmap files or paste your mipmap copy files.. simple”
 

 

 
 
AndroidManifest.xml
If you want to change app icon then change this…..
——————————————————————-
 
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.add">

<

application
        android:allowBackup="true"
        android:icon="@mipmap/addicon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/addicon"
        android:supportsRtl="true"
        android:theme="@style/Theme.Add">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

<

category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</

manifest>