Tuesday, 5 January 2016

Snackbar in Android (Material design)

Screen Shot:

This is Android Studio Project:

Include following dependency in your build.gradle file

build.gradle:
 apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.ramsandroid.snackbarexample"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.0.1'
}



activity_main.java:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ramsandroid.snackbarexample.MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Snack Bar"
        android:id="@+id/button_snackbar"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="63dp" />
</RelativeLayout>

MainActivity.java:
package com.ramsandroid.snackbarexample;

import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button snackBarButton = (Button) findViewById(R.id.button_snackbar);
        snackBarButton.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View v) {
                Snackbar snackbar = Snackbar.make(v, "Snackbar working", Snackbar.LENGTH_LONG);
                snackbar.show();

            }
        });
    }
}

20 comments:

  1. Thank you for giving the information and it is use full for me. training with placement company in Hyderabad

    ReplyDelete

  2. I always enjoy reading quality articles by an individual who is obviously knowledgeable on their chosen subject. Ill be watching this post with much interest. Keep up the great work, I will be back
    Android Training Institute in Noida
    Python Training Classes in Noida

    ReplyDelete
  3. Very nice post now you can use VipFB to increase fb likes

    ReplyDelete
  4. Make sure your website doesn't contain 404 error pages. Every blogger wants to display his/her page on the first page of the google. In this process i've followed forums, pdf submissions, directory submissions and many more. You also try it out and reach your blog to the abounding online communities and eventually get the fruitful results.
    Watch your favorite TV Shows and movies exclusively on Morpheus TV
    Morpheus TV Apk Highlights
    Morpheus TV Intriguing Features
    Download Morpheus TV

    ReplyDelete
  5. Today Telugu news updates provide us the information of breaking news and live updates. we get live news, political, education, technology, etc. Today Telugu news gives the best news updates. It also keeps its readers informed about the latest happenings in the world with instant updates.

    ReplyDelete
  6. Really an awesome blog for the freshers. Thanks for posting the information.
    Android Training in Delhi
    Android Course in Delhi

    ReplyDelete
  7. very informative blog and useful article thank you for sharing with us , keep posting learn more Technology
    Android Training
    Android App development Course
    Android Online Training

    ReplyDelete
  8. Your content is very nice. Check out our blog on Android Course

    ReplyDelete
  9. You are doing a fantastic job and sharing your knowledge to others! it was one of the very good post to read and useful to improve the knowledge as updated one, keep doing the nice work. Android Training in Electronic City

    ReplyDelete
  10. You are making an incredible showing and imparting your insight to other people! Cooking Madness

    ReplyDelete
  11. Waoo This is the best ever example i liked it for more Click here to download
    you can also download Antena View Apk Free Download

    ReplyDelete
  12. free android app download.The best apps download games ,file manager , youtube video downloader . Android blue

    ReplyDelete
  13. Download the Home School App which is one of the best Online Teaching App on Google Playstore. Teach students in a interactive way by recording educational videos and by sharing it with them on the Home School App. You can also save educational videos on the app for best offline learning.

    ReplyDelete
  14. Thank you for discussing this very useful article. I heard something new from you. Keep blogging. android training in jalandhar

    ReplyDelete