How to create Cardview with Toast | Cardview | Toast | Android Studio.


How to create Cardview with Toast 


1)Open the Android Studio.
2)Go to build.gradle (module app)
3)In import dependencies the cardview implementation
 (implementation 'androidx.cardview:cardview:1.0.0')
4)Click on sync.
5)Then come to Layout file and start writing the code for cardview.
6)Go-to java file and decleare the cardview.
7)Set the path for cardview.
8)Then set the click activity and write the code for Toast.
9)Run the emulator(check the output).

Code for Xml file:-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".homeactivity">
<androidx.cardview.widget.CardView
    android:layout_width="160dp"
    android:layout_height="190dp"
    android:id="@+id/theacx">
 <ImageView
        android:layout_width="120dp"
        android:layout_height="104dp"
        android:src="@drawable/logo"
        android:layout_margin="20dp"/>
 <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginTop="135dp"
        android:layout_marginLeft="10dp"
        android:background="#000"
        android:layout_marginRight="10dp"/>
 <TextView
        android:layout_width="match_parent"
        android:layout_marginTop="145dp"
        android:text="THE ACX"
        android:textSize="27dp"
        android:textAlignment="center"
        android:textColor="#000"
        android:layout_height="wrap_content"/>
</androidx.cardview.widget.CardView>

</LinearLayout>

In gradle file import dependencies the cardview implementation
 (implementation 'androidx.cardview:cardview:1.0.0')

Toast:-
Toast.makeText(homeactivity.this,"TheACX",Toast.LENGTH_LONG).show();

Code for java file:-
package com.example.theacx;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class homeactivity extends AppCompatActivity {
    CardView cardView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_homeactivity);
        cardView=findViewById(R.id.theacx);

        cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i =new Intent(homeactivity.this,demo.class);
                Toast.makeText(homeactivity.this,"The ACX",Toast.LENGTH_LONG).show();
                startActivity(i);
            }        });
    }}

Comments

Popular posts from this blog

How to install Pip pillow | Install Pip Pillow | Python pip | Python pillow tutorial

How to create Splashscreen | Android Studio.