colors.xml和多个模块

我在通用模块中有3个模块(common,app1,app2),我希望布局在app1中为黑色,在app2中为白色。

Layout.xml

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:baselineAligned="false"
        android:orientation="horizontal"
        android:padding="16dp"
        android:background="@color/myColorBackground"
        android:weightSum="4">
...

App1 colors.xml

<ressources>
   <color name="myColorBackground">#fff</color>
</resources>

App2 colors.xml

<ressources>
   <color name="myColorBackground">#000</color>
</resources>

当我尝试构建应用程序时,我崩溃了。是否有使用这种颜色的解决方案?

chenhui1646 回答:colors.xml和多个模块

使用模块时,您需要在每种类型中添加相同的文件,或者在主模块中使用通用文件并覆盖所需模块中的特定文件。see the image and add files properly

,

通过在我的通用模块中添加<color name="myColorBackground"/>,我发现了一种解决方法,现在一切正常!

本文链接:https://www.f2er.com/2963008.html

大家都在问