Reputation: 561
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 error retrieving parent...
for the theme parent in styles.xml
.
I change it to android: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 a Snackbar
but I get an error because Snackbar cannot be resolved
.
Please somebody help me! I'm going crazy, what am I doing wrong?
Upvotes: 7
Views: 24184
Reputation: 663
Add this in your build.gradle (Module: app) inside dependencies:
implementation 'com.android.support:design:28.0.0'
or
implementation 'com.dmitrymalkovich.android:material-design-dimens:1.4'
Complete code:
dependencies {
implementation 'com.android.support:design:28.0.0'
}
or
dependencies {
implementation 'com.dmitrymalkovich.android:material-design-dimens:1.4'
}
Upvotes: 0
Reputation: 365038
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()
})
Upvotes: 40
Reputation: 1489
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.
Upvotes: 1
Reputation: 3995
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.
Upvotes: 6
Reputation: 311
For Eclipse Developers
build path > add as source folder
add these lines/change SnackBar project's AndroidManifest.xml
as follows
<uses-sdk android:minSdkVersion="7"
android:targetSdkVersion="22"/>
<application />
package="com.nispok.snackbar"
dependencies
to the SnackBar projectandroid-support-v7-appcompat: 21
android-support-v7-recyclerview: 21
That's it will be working for you, Have a great coding day..
Upvotes: 0
Reputation: 6078
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.
Upvotes: 11