如何从库样式继承样式?

时间:2016-11-20 10:38:02

标签: android android-layout inheritance android-styles android-library

我想在我的项目中使用NumberProgressBar库。

我以这种方式将它添加到gradle中:

dependencies {
   compile 'com.daimajia.numberprogressbar:library:1.2@aar'
}

它有预定义的样式,据说你可以轻松地使用它:

 <com.daimajia.numberprogressbar.NumberProgressBar
        android:id="@+id/number_progress_bar"
        style="@style/NumberProgressBar_Default"
  />

我想根据库样式编写自己的样式,我无法从styles.xml文件中访问它:

<style name="CustomProgressBar" parent="NumberProgressBar_Beauty_Red"/>

Error:(2220) Error retrieving parent for item: No resource found that matches the given name 'NumberProgressBar_Beauty_Red'.

我尝试了几种不同的方式来访问它,使用命名空间,但它仍然无法正常工作。

甚至可以从库中继承样式吗?访问库样式的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

您确定以正确的方式添加了依赖项并执行了Gradle Sync吗?

如果不是,请按照以下步骤操作:

  1. 档案 - &gt; 项目结构......
  2. 选择左侧的应用模块,然后选择依赖关系标签。
  3. 使用右侧的绿色+按钮,然后选择图书馆相关性
  4. 粘贴com.daimajia.numberprogressbar:library:1.2@aar
  5. 确定确定
  6. 如果你想比较,这是我的 build.gradle(模块:app)

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        compile 'com.android.support:appcompat-v7:24.2.1'
        testCompile 'junit:junit:4.12'
        compile 'com.daimajia.numberprogressbar:library:1.2@aar'
    }
    
相关问题