【问题标题】:How do I modify a resource file of an external library included in my project?如何修改项目中包含的外部库的资源文件?
【发布时间】:2018-04-04 19:30:14
【问题描述】:

https://github.com/Gericop/Android-Support-Preference-V7-Fix/blob/master/preference-v7-simplemenu/src/main/res/layout/preference_simplemenu.xml

我在我的 Android 应用项目中包含了 Android Preference-v7 修复库,我想更改此 xml 中的一些内容。更具体地说,我想将菜单和摘要文本视图向右对齐。如何让应用使用我的 xml 文件而不是库中的文件?

我的毕业生:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "app.test.testapp"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '27.0.3'
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.takisoft.fix:preference-v7-simplemenu:+'
    compile 'com.takisoft.fix:preference-v7:27.1.0.0'
}

【问题讨论】:

    标签: java android android-studio android-gradle-plugin gradle-plugin


    【解决方案1】:

    如果您没有提取任何新的 lib 副本,那么您可以手动替换 jar 中的文件一次,然后使用编辑后的 ​​jar。

    如果您在构建过程中提取库,那么您可以在构建过程中以编程方式将文件替换为您自己的文件。

    也许向我们展示您的构建过程?您是否需要此文件与 repo 上的版本保持同步(您的更改除外)?

    【讨论】:

    • 我不知道如何或何时拉它,我只是按照说明操作,它说将以下行添加到 gradle:compile 'com.takisoft.fix:preference-v7 :27.1.0.0' 一切(神奇地)开始正常工作。我很乐意在构建过程中替换文件,因为它似乎是最简单的方法,并且每当原始文件在 github 上更新时,我都可以编辑差异。还有这一行我应该用于这个菜单: implementation 'com.takisoft.fix:preference-v7-simplemenu:+'
    • @RafaelJ 请发布您的完整 gradle 脚本
    • @RafaelJ 我承认我不熟悉 gradle,生成的 jar 是什么样的?我打赌你可以直接复制和编辑你想要的文件,然后将它们包含在implementation fileTree(include: ['*.xml'], dir: 'fixed_preferences') 之类的东西中。
    • 好的,我明白了。我做了类似于你建议的事情。在我的例子中,布局 id(“preference_simplemenu.xml”)是在 styles.xml 文件中声明的,所以我所要做的就是将 <style name="Preference.SimpleMenuPreference"> <item name="android:layout">@layout/pref_simplemenu_fix</item> </style> 添加到 styles.xml 并且我自己修改的 simplemenu 修复位于布​​局文件夹中。
    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多