 
        سلام دوستان در این آموزش میخام بهتون آموزش بدم که چگونه
از SnackBar در برنامه نویسی اندروید استفاده کنیم
خب در پایین یک مثال از SnackBar براتون نوشتم
res/layout/activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="روی دکمه زیر کلیک کنید تا snackBar ظاهر شود" />
    <Button
        android:id="@+id/callbackButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_below="@id/textView"
        android:layout_marginTop="16sp"
        android:text="کلیک کنید"
        android:textStyle="bold"
        android:textSize="16sp"/>
</RelativeLayout>
در بالا همونطور که میبینید یک TextView و یک Button ایجاد کردم
حالا نوبت میرسه به اضافه کردن کتابخانه در gradle البته اگر از اندروید X استفاده می کنید لازم نیست این کتابخانه را به پروژه خود اضافه کنید
زیرا در اندروید X این design به برنامه اضافه شده است
(build.gradle(Module app
implementation 'com.android.support:design:28.0.0'
قدم بعدی نوشتن کدهای جاوا
src/MainActivity.java
package com.hamyarandroid.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = findViewById(R.id.callbackButton);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Snackbar snackBar = Snackbar .make(v, "HamyarAndroid", Snackbar.LENGTH_LONG) .setAction("OK", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                    }
                });
                snackBar.setActionTextColor(Color.BLUE);
                View snackBarView = snackBar.getView();
                TextView textView = snackBarView.findViewById(R.id.snackbar_text);
                textView.setTextColor(Color.RED);
                snackBar.show();
            }
        });
    }
}
