Android Bootstrap 和 Android studio 无法添加库

标签 android android-studio android-activity android-bootstrap-widgets

我想添加 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 同步

sync project with 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 结帐)

https://github.com/pyus-13/TesstApp.git

关于Android Bootstrap 和 Android studio 无法添加库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21067796/

相关文章:

java - Android - 将 HTML 分享到 WhatsApp 和电子邮件

android - 使用原始 keystore 但不同项目更新 Android 应用程序

c# - $(TargetFrameworkVersion) (v9.0) 小于 Xamarin.Forms (10.0) 所需的最低 $(TargetFrameworkVersion)

android-studio - 由于尝试生成签名的APK,Android Studio将不会调试(仅构建)

java - 无法在 dex 路径列表中找到该类

java - 开始另一个 Activity - 应用程序崩溃

java - Android 定时器不精确

android - 在Android Studio中构建统一项目(具有Firebase)时出错

android - 如何取消onPause或onStop方法?

android - 允许不安全的协议(protocol),android gradle