切换到gradle后,android自定义视图属性不起作用

Mar*_*ars 13 android attributes gradle android-custom-view

所以我最近迁移到gradle现在我的自定义视图属性返回null

我的项目看起来像这样

--custom_icon_view //保存带有自定义属性的自定义视图的库 - 我的应用程序//这是实际使用自定义视图的主应用程序

在我的布局中,我有如下定义的命名空间:

        xmlns:iconview="http://schemas.android.com/lib/be.webelite.iconview"
Run Code Online (Sandbox Code Playgroud)

因为使用apk/res-auto返回错误,无法识别attibutes

这就是我尝试获取在xml中定义的图标名称的方法,这用于完美地工作,但现在它没有.而我改变的只是迁移到gradle.

        final TypedArray a              = context.obtainStyledAttributes(attrs,be.webelite.iconview.R.styleable.icon);
        icon_name = a.getString(be.webelite.iconview.R.styleable.icon_name);
Run Code Online (Sandbox Code Playgroud)

所以我猜我的gradle.build文件导致了问题?

我把库设置为

  apply plugin: 'android-library'
Run Code Online (Sandbox Code Playgroud)

结束主应用程序gradle.build为

  apply plugin: 'android'
Run Code Online (Sandbox Code Playgroud)

这让我头疼2天了:(任何帮助/提示非常适合.

这是我的gradle文件

http://pastie.org/private/h57o8nanydosq0dtm6eiq

这是文件夹结构

http://pastie.org/private/nvbzomx2zeagdpzt8qqjsq

这是我在xml中声明我的视图的方式

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    <!-- tried res-auto didn't work -->
    xmlns:iconview="http://schemas.android.com/apk/lib/be.webelite.iconview"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_gray">

    <be.webelite.iconview.IconView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        iconview:icon_name="entypo_search"
        android:textSize="25dp"/>
Run Code Online (Sandbox Code Playgroud)

IconView> res> values目录中的attrs.xml

        <?xml version="1.0" encoding="utf-8"?>
        <resources>
            <declare-styleable name="icon">
                <attr name="name" format="string" />
            </declare-styleable>

        </resources>
Run Code Online (Sandbox Code Playgroud)

And*_*ros 19

无法真正看出你的项目有什么问题.以下是我如何使用我的自定义视图和attrs:

在我的图书馆项目中:

attrs.xml:

<declare-styleable name="CustomFontSize">
    <attr name="typeFace" format="string" />
</declare-styleable>
Run Code Online (Sandbox Code Playgroud)

在我的自定义类中:

 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomFontSize);
 if (a == null) {
      return;
 }
 CharSequence s = a.getString(R.styleable.CustomFontSize_typeFace);
 if (s != null) {
    // do something
 }
Run Code Online (Sandbox Code Playgroud)

在我的主项目中,我的一个布局示例:

<LinearLayout 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="wrap_content"
              android:orientation="vertical"
              android:paddingLeft="@dimen/border_margin_pulltorefresh"
              android:paddingRight="@dimen/border_margin_pulltorefresh"
              android:paddingBottom="@dimen/divider_height">


    <com.custom.view.TextViewFont
            style="@style/DateStyle"
            android:id="@+id/news_date"
            android:shadowColor="@color/white"
            android:layout_gravity="center_vertical"
            android:gravity="center_vertical"
            custom:typeFace="@string/font_roboto_condensed_bold"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

希望它会有所帮助......

编辑:

在我的"主要项目"的build.gradle中

dependencies {
    compile project(":MyLibraryProject")
}
Run Code Online (Sandbox Code Playgroud)

在这里我的库的build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.7.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile project(':WebediaCore:dependencies:DataDroid')
    compile project(':WebediaCore:dependencies:ViewPagerIndicator')
    compile project(':WebediaCore:dependencies:ActionBar-PullToRefresh')
    compile project(':WebediaCore:dependencies:Android-Universal-Image-Loader')
}

android {
    compileSdkVersion 19
    buildToolsVersion '19'

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑1:

尝试使用此命名空间:

xmlns:custom="http://schemas.android.com/apk/res-auto"
Run Code Online (Sandbox Code Playgroud)

并替换:

 iconview:icon_name="entypo_search"
Run Code Online (Sandbox Code Playgroud)

通过:

 custom:name="entypo_search"
Run Code Online (Sandbox Code Playgroud)