Snackbar with API 21
Solution 1
You should try to use Android Studio, because the ADT plugin for Eclipse is no longer in active development.
In Android Studio, you just need to add a line compile 'com.nispok:snackbar:2.6.1'
in your build.gradle
dependencies, such that
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.nispok:snackbar:2.6.1'
}
That's it.
Solution 2
With the new Design Support Library you can use the official SnackBar Widget.
Just add this dependency to your app -> build.gradle
:
implementation 'com.android.support:design:28.0.0'
And use something like:
Snackbar.make(view, "Snackbar", Snackbar.LENGTH_LONG).show();
Full Example, In Kotlin
val fab = findViewById(R.id.btn_signin) as Button
fab.setOnClickListener(View.OnClickListener { view ->
Snackbar.make(view, "FloatingActionButton is clicked", Snackbar.LENGTH_INDEFINITE)
.setAction("Action", null).show()
})
Solution 3
If you are facing "not resolved to a type" issue in Eclipse for Snackbar, this worked for me.
Right click on Project->BuildPath->Configure Buildpath Click on Libraries Tab and then click on Add external Libraries.
Select {path of adt}/sdk/extras/android/support/design/libs Select android-support-design.jar, Click Open to add this library.
Click Ok.
Solution 4
Please add the below code to the build.gradle file
implementation 'com.android.support:design:28.0.0'
after that Click the Sync Now button,It will work.
Related videos on Youtube
Comments
-
MattButtMatt about 3 years
I'm trying to implement the new Snackbars in my app but I can't. First of all I downloaded the zip file from this SnackBarSampleActivity.
I unziped it and then I import it in Eclipse. Now I get an errorretrieving parent...
for the theme parent instyles.xml
.
I change it toandroid:Theme.Light
and the error was gone. I right clicked the project and checked isLibrary in Properties/Android, I right clicked my app and in Properties/Android I add the library. Finally I paste the code to show aSnackbar
but I get an error becauseSnackbar cannot be resolved
.
Please somebody help me! I'm going crazy, what am I doing wrong? -
MattButtMatt almost 9 yearsI think I'll give it a try. In general is it similar to eclipse?
-
bjiang almost 9 yearsSure it is, it better than eclipse, such as Auto-complete and Extract, and now is a official IDE
-
bjiang almost 9 yearsHave you tried? If it works, plz mark this answer as best, thx
-
MattButtMatt almost 9 yearsLater today I'll try it and if it works I'll mark your answer, don't worry :)
-
Raghunandan over 8 yearsDoes this apply to FloatingActionButton also?
-
Raghunandan over 8 years
-
Gabriele Mariotti over 8 years@Raghunandan Yes. it can work with the official FAB.
-
KUSHA B K about 5 yearscan you please explain more about what you have done?