我想添加 Android Bootstrap library到我使用 Android Studio 的项目(我关注了 this tutorial )。
我在项目资源管理器中看到了 Android Bootstrap 和我的项目,但是如果我尝试添加一个引导按钮
<!-- basic button -->
<com.beardedhen.androidbootstrap.BootstrapButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Success"
bootstrapbutton:bb_icon_right="fa-android"
bootstrapbutton:bb_type="success"
/>
我收到以下错误消息:
android-apt-compiler: layout/activity_main.xml:56: error: No resource identifier found for attribute 'bb_icon_right' in package 'com.carfinder'
我做错了什么?
最佳答案
更新:
确保你的项目结构应该是这样的,你的库可以在某个目录中,比如 libraries>AndroidBootStrapLibrary 没问题,在这种情况下你只需要更改 settings.gradle 和 build.gradle 中的路径
----YOUR_PROJECT
---AndroidBootStrapLibrary
--res
--src
-- .....
-- build.gradle(must contain apply plugin: 'android-library'
if not that menas not library project you have added something wrong)
---YOUR_MODULE
--res
--src
--build.gradle (no : A)
----settings.gradle
build.gradle(A号)文件
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:18.0.+'
compile project(':AndroidBootStrapLibrary')
}
设置.gradle :
include ':YOUR_MODULE'
include ':AndroidBootStrapLibrary'
完成后将项目与 Gradle 同步
您忘记为库中的自定义 View 添加命名空间。
用这个替换你的按钮代码
<com.beardedhen.androidbootstrap.BootstrapButton
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Success"
bootstrapbutton:bb_icon_right="fa-android"
bootstrapbutton:bb_type="success"
/>
如果您正在使用,也可以在其他 View 中添加命名空间。您也可以将它添加到布局文件的根元素中,例如
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.app.MainActivity$PlaceholderFragment">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.beardedhen.androidbootstrap.BootstrapButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Success"
bootstrapbutton:bb_icon_right="fa-android"
bootstrapbutton:bb_type="success"
/>
</RelativeLayout>
我在这里上传了一个工作测试项目(在 AS 中通过 github 结帐)
关于Android Bootstrap 和 Android studio 无法添加库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21067796/