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?
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.
make(parentlayout, "This is main activity", Snackbar. LENGTH_LONG) . setAction("CLOSE", new View. OnClickListener() { @Override public void onClick(View view) { } }) .
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With