Snackbar with API 21

↘锁芯ラ 提交于 2019-12-04 05:46:17
bjiang

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.

Gabriele Mariotti

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()
        })

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.

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.

For Eclipse Developers

  1. Follow the instructions given in github to import SnackBar project
  2. Right click on the java folder and click build path > add as source folder
  3. add these lines/change SnackBar project's AndroidManifest.xml as follows

    <uses-sdk android:minSdkVersion="7"
        android:targetSdkVersion="22"/>
    <application />
    

package="com.nispok.snackbar"

  1. Add following dependencies to the SnackBar project

android-support-v7-appcompat: 21
android-support-v7-recyclerview: 21

  1. Finally set Project build target to API 22 in project properties.

That's it will be working for you, Have a great coding day..

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'
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!