Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Snackbar without support library?

I am developing an Android app which doesn't require backward compatibility. Target SDK version is 22 as of now. I am using native Activity and Fragment and application theme is android:Theme.Material.Light. My problem is that I'm not able to use Snackbar with the existing setup, it throws exceptions like

android.view.InflateException: Binary XML file line #18: Error inflating class android.support.design.widget.Snackbar$SnackbarLayout E/AndroidRuntime(19107): at android.view.LayoutInflater.createView(LayoutInflater.java:640) E/AndroidRuntime(19107): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)

I googled but couldn't find any example of snackbar with Activity. So is it necessary to use support library like

AppCompatActivity or android.support.v4.app.Fragment.

in order to use Snackbar in my app?

like image 990
Amit Avatar asked Jan 14 '16 07:01

Amit


People also ask

How do I use snackbar?

This will define the button and add a onClickListener to the button. In the onClickListener a Snackbar is created and is called. So whenever the button is clicked, the onClickListener creates a snackbar and calls it and the user sees the message. This snackbar contains an action and if clicked will show a toast.

How do I get view on snackbar?

make(parentlayout, "This is main activity", Snackbar. LENGTH_LONG) . setAction("CLOSE", new View. OnClickListener() { @Override public void onClick(View view) { } }) .

What is snackbar explain it with example?

com.google.android.material.snackbar.Snackbar. Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom of the screen on mobile and lower left on larger devices. Snackbars appear above all other elements on screen and only one can be displayed at a time.


1 Answers

You need to use the support design library compile 'com.android.support:design:23.0.1' for it to work:

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

(Read more in detail here)

like image 198
AndroidMechanic - Viral Patel Avatar answered Oct 06 '22 00:10

AndroidMechanic - Viral Patel