Program 1-Hello Toast: Strings
Program 1-Hello Toast: Strings
Program 1-Hello Toast: Strings
XML
Strings:
<resources>
<string name="app_name">My Application</string>
<string name="button_label_toast">TOAST</string>
<string name="button_label_count">COUNT</string>
<string name="count_initial_value">0</string>
<string name="toast_message">Hello Toast!</string>
<string name="name">Shrinivas</string>
<string name="reg_no">2047123</string>
</resources>
Colors:
Toast:
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="#FFF" />
</LinearLayout>
activity_main:
<?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="#673AB7"
tools:context=".MainActivity">
<TextView
android:id="@+id/regno"
android:layout_width="232dp"
android:layout_height="105dp"
android:gravity="center_horizontal|center_vertical"
android:text="@string/reg_no"
android:textColor="#0F0F10"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toTopOf="@+id/show_count"
app:layout_constraintEnd_toStartOf="@+id/imageView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/show_count"
android:layout_width="411dp"
android:layout_height="wrap_content"
android:background="#0DBF14"
android:gravity="center"
android:text="@string/count_initial_value"
android:textColor="@color/purple_700"
android:textSize="160sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/btn2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/btn1"
android:layout_width="414dp"
android:layout_height="63dp"
android:background="@color/purple_700"
android:onClick="show_toast"
android:text="@string/button_label_toast"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn2"
android:layout_width="414dp"
android:layout_height="63dp"
android:background="@color/purple_700"
android:onClick="count_up"
android:text="@string/button_label_count"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/name"
android:layout_width="234dp"
android:layout_height="116dp"
android:gravity="center_horizontal|center_vertical"
android:text="@string/name"
android:textColor="#111112"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintBottom_toTopOf="@+id/show_count"
app:layout_constraintEnd_toStartOf="@+id/imageView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn1"
app:layout_constraintVertical_bias="0.291" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="177dp"
android:layout_height="386dp"
app:layout_constraintBottom_toTopOf="@+id/show_count"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btn1"
app:srcCompat="@drawable/pic" />
</androidx.constraintlayout.widget.ConstraintLayout>
JAVA
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private int count = 0;
private TextView showc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showc = (TextView) findViewById(R.id.show_count);
}
}
Screen shots:
With toast: