【问题标题】:can't access the class from ActionBar-PullToRefresh library无法从 ActionBar-PullToRefresh 库访问该类
【发布时间】:2014-08-27 16:29:32
【问题描述】:

我在一个 android 项目上,我需要导入 ActionBar-PullToRefresh 库,所以我使用 gradle 导入该库,如下所示:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('com.android.support:appcompat-v7:20.0.0') {
        force = true
    }
    compile('com.android.support:support-v4:20.0.0') {
        force = true
    }
    repositories {
        mavenCentral()
    }
    compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}

然后我Sync Project with Gradle Files,所以我可以在我的布局xml文件中使用PullToRefreshLayout。但是当我在我的片段代码中使用库的类时,我无法得到任何代码触发器。当我拼写整个类名PullToRefreshLayout 时,Android Studio 不会自动导入该类。那么问题来了。

接下来的两个文件是我根目录下的build.gradle文件和我的app目录:

根目录下的build.gradle文件

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

app目录下的build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.ifeve.ifeveforandroid"
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}



dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('com.android.support:appcompat-v7:20.0.0') {
        force = true
    }
    compile('com.android.support:support-v4:20.0.0') {
        force = true
    }
    repositories {
        mavenCentral()
    }
    compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abc:+'
}

【问题讨论】:

  • ChrisBanes PullToRefresh 已弃用。我建议使用来自 Google 的 SwipeRefreshLayoutReferenceExample
  • @MartinCR 是的,但是 SwipeRefreshLayout 不支持在 ActionBar 上添加提示“拉动刷新”——这也是我使用这个库的原因。
  • G+ 也是 ChrisBanes pull2refresh 风格。我也不喜欢 SwipeRefreshLayout 触摸“反弹”效果。
  • @MartinCR 是的,我尝试了 SwipeRefreshLayout 但无法获得理想的效果。

标签: android android-studio pull-to-refresh android-actionbar-compat


【解决方案1】:

尝试以这种方式导入库,在 dependencies 部分添加这一行:

compile 'com.github.chrisbanes.actionbarpulltorefresh:library:0.9.9'

【讨论】:

  • 我需要 actionbar-compact 支持。我不能只导入没有 actionbar-compact 支持的库。
  • 我正在使用 abs 支持,我使用上面的那一行,它对我有用。试试看。
  • 不需要添加 actionbar-compact 支持吗?只有一行?
猜你喜欢
  • 2014-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-12
  • 1970-01-01
相关资源
最近更新 更多