Android主工程找不到Library attrs中的资源文件

小问题,做个记录。

布局文件中引用自定义属性及其命名空间通常如下所示:

<com.hailong.library.gesturelock.PatternView
            android:id="@+id/patternView"
            android:layout_width="300dp"
            android:layout_height="300dp"
            android:layout_below="@id/layout_framelayout"
            android:layout_centerHorizontal="true"
            app:gridSize="3"
            app:pathColor="#f2c68d" />
xmlns:app="http://schemas.android.com/apk/res/android"

如果自定义属性来源于Library,那么上面的gridSize和pathColor会报错,需要修改命名空间,如下所示:

xmlns:app="http://schemas.android.com/apk/res-auto"

 

Android开发,引用其他aar库的源文件需要进行一些操作才能显示出来。 首先,我们需要在项目的build.gradle文件添加对aar库的依赖。在dependencies块,添加类似以下的代码: ```groovy implementation(name: 'library-aar', ext: 'aar') ``` 然后,在项目的AndroidManifest.xml文件,添加以下代码: ```xml <meta-data android:name="com.library.aar.SampleApplication" android:value="Resource"/> ``` 接下来,我们需要在项目的res/values目录下的attrs.xml文件声明aar库使用的自定义属性。例如: ```xml <attr name="sampleAttribute" format="string"/> ``` 接着,在项目的res/layout目录下的layout.xml文件引用aar库的源文件。例如: ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:custom="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" custom:sampleAttribute="sampleValue" /> </RelativeLayout> ``` 最后,我们需要在项目的MainActivity.java文件到对应的控件,并设置aar库源文件。例如: ```java TextView textView = findViewById(R.id.textView); textView.setText(getResources().getString(R.string.sample_resource)); ``` 上述是对于引用aar库源文件的一般操作,但是在实际开发还可能会遇到其他问题,比如aar库的版本兼容性等。如果上述操作无法解决问题,还需要进一步查原因及解决方案。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值