Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snackbar package in AndroidX

When migrating a project or switching between branches which are and aren't migrated, Android Studio cannot build projects because it cannot find the android.support.design.widget.Snackbar package. Support/Design packages are removed but the migration table does not list the correct new package for this component.

like image 758
Nick Cardoso Avatar asked Oct 01 '18 14:10

Nick Cardoso


People also ask

What is snackbar used for?

Snackbar in android is a new widget introduced with the Material Design library as a replacement of a Toast. Android Snackbar is light-weight widget and they are used to show messages in the bottom of the application with swiping enabled. Snackbar android widget may contain an optional action button.

How do I increase my snackbar time?

The duration should be LENGTH_SHORT, LENGTH_LONG or LENGTH_INDEFINITE. When LENGTH_INDEFINITE is used, the snackbar will be displayed indefinite time and can be dismissed with swipe off. And you can set the duration of your snackbar by setDuration(int) method.

How do you use kotlin snackbar?

This example demonstrates how to use Snackbar in Android Kotlin. Step 1 − Create a new project in Android Studio, go to File ⇉ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.

How do I use snackbar in Android?

This example demonstrates how do I use snackBar in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml. Step 3 – Open build.gradle (Module app) add the following dependancy -

How to create a snackbar in Android with onclicklistener?

Now add the following code in the MainActivity.java file. 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.

What is the snackbar action button used for?

The Snackbar action button should be used for lightweight user interaction. i.e. instantaneous actions. In conclusion, Snackbar is very handy and useful for alerting the user over an action recently performed, and providing an option for reversal of recently performed action.

What is a snackbar?

In this tutorial we will explore simple step by step SnackBar examples. What is a SnackBar? Snackbars are part of the material design android widgets and do 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.


4 Answers

This took a long time to resolve, as until your project successfully builds, autocomplete will not function to lookup packages.

The correct package to use is:

com.google.android.material.snackbar.Snackbar

It is also important to remember to change this on the XML tags as well as the imports if the migration has not worked successfully.

like image 156
Nick Cardoso Avatar answered Oct 18 '22 03:10

Nick Cardoso


Old build artifact com.android.support:design now solves in com.google.android.material:material:1.0.0 for AndroidX build artifact.

like image 20
Nicola Gallazzi Avatar answered Oct 18 '22 04:10

Nicola Gallazzi


Add implementation "com.google.android.material:material:1.1.0" to your app-level build.gradle.

Also, ensure that your project is set up to migrate old packages to Androidx by including this in your gradle.properties file:

android.useAndroidX=true android.enableJetifier=true

like image 39
Dennis Murage Avatar answered Oct 18 '22 05:10

Dennis Murage


Import

com.google.android.material.snackbar.Snackbar;

instead of

android.support.design.widget.Snackbar;

if you shifted to androidx and AS couldn't find the package anymore.

like image 21
Derryl Thomas Avatar answered Oct 18 '22 05:10

Derryl Thomas