Java 带有 API 21 的小吃店

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27488826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:27:15  来源:igfitidea点击:

Snackbar with API 21

javaandroideclipsematerial-designandroid-design-library

提问by BlueMango

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.Lightand 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 Snackbarbut I get an error because Snackbar cannot be resolved.
Please somebody help me! I'm going crazy, what am I doing wrong?

我正在尝试在我的应用程序中实现新的 Snackbars,但我不能。首先,我从这个 SnackBarSampleActivity下载了 zip 文件。
我解压了它,然后将它导入到 Eclipse 中。现在我retrieving parent...styles.xml.
我将其更改为android:Theme.Light,错误消失了。我右键单击该项目并在 Properties/Android 中检查 isLibrary,我右键单击我的应用程序并在 Properties/Android 中添加库。最后我粘贴代码以显示 aSnackbar但我收到一个错误,因为Snackbar cannot be resolved.
请有人帮助我!我快疯了,我做错了什么?

采纳答案by bjiang

You should try to use Android Studio, because the ADT plugin for Eclipse is no longer in active development.

您应该尝试使用 Android Studio,因为 Eclipse 的 ADT 插件不再处于活动开发状态。

In Android Studio, you just need to add a line compile 'com.nispok:snackbar:2.6.1'in your build.gradledependencies, such that

在 Android Studio 中,你只需要compile 'com.nispok:snackbar:2.6.1'在你的build.gradle依赖项中添加一行,这样

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.

就是这样。

回答by Asrin

For Eclipse Developers

对于 Eclipse 开发人员

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

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

  1. 按照github中给出的说明导入SnackBar项目
  2. 右键单击java文件夹,然后单击build path > add as source folder
  3. 添加这些行/更改 SnackBar 项目AndroidManifest.xml如下

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

package="com.nispok.snackbar"

包=“com.nispok.snackbar”

  1. Add following dependenciesto the SnackBar project
  1. 将以下内容添加dependencies到 SnackBar 项目中

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

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

  1. Finally set Project build target to API 22 in project properties.
  1. 最后在项目属性中将项目构建目标设置为 API 22。

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

这就是它对你的工作,祝你编码愉快..

回答by Gabriele Mariotti

With the new Design Support Libraryyou can use the official SnackBarWidget.

通过新的设计支持库,您可以使用官方的SnackBar小部件。

Just add this dependency to your app -> build.gradle:

只需将此依赖项添加到您的app -> build.gradle

implementation 'com.android.support:design:28.0.0'

And use something like:

并使用类似的东西:

Snackbar.make(view, "Snackbar", Snackbar.LENGTH_LONG).show();

enter image description here

在此处输入图片说明

Full Example, In Kotlin

完整示例,在 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()
        })

回答by Junaid

If you are facing "not resolved to a type" issue in Eclipse for Snackbar, this worked for me.

如果您在 Eclipse for Snackbar 中遇到“未解决类型”问题,这对我有用

Right click on Project->BuildPath->Configure Buildpath Click on Libraries Tab and then click on Add external Libraries.

右键单击 Project->BuildPath->Configure Buildpath 单击 Libraries 选项卡,然后单击 Add external Libraries。

Select {path of adt}/sdk/extras/android/support/design/libs Select android-support-design.jar, Click Open to add this library.

选择{path of adt}/sdk/extras/android/support/design/libs 选择android-support-design.jar,点击打开添加这个库。

Click Ok.

单击确定。

Final Window

最终窗口

回答by KUSHA B K

Please add the below code to the build.gradlefile

请将以下代码添加到build.gradle文件中

implementation 'com.android.support:design:28.0.0'

after that Click the Sync Now button,It will work.

之后单击“立即同步”按钮,它将起作用。

回答by rohegde7

Add this in your build.gradle (Module: app) inside dependencies:

将此添加到您的 build.gradle (Module: app) 内的依赖项中:

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'
}