I am trying to access a library that contains some strings and drawables. In my main project I add the library as a module. The problem is that when I want to reference in a layout to a string or a color resource, I can't. According to the guide of the API syntax, I use @[package.of.the.library]:type/resource_name, but this does not work.
I add an example of the layout that I use for testing:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mylibrary="http://schemas.android.com/apk/com.mylibrary.resources"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@mylibrary:string/testing_text" />
</LinearLayout>
I have tried using xmlns:mylibrary="http://schemas.android.com/apk/res-auto" instead of xmlns:mylibrary="http://schemas.android.com/apk/com.mylibrary.resources" but it doesn't work.
You need to add compile project(":mylibrary") to your app build.gradle file dependencies.
dependencies {
compile project(":mylibrary")
...rest of dependencies for project
}
First add the module as dependency to main project build.gradle file
compile project(":module_name")
where module_name is name of module project
and then u can access string or color just like normal string and color
@string/testing_text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With