【发布时间】:2016-06-29 02:24:41
【问题描述】:
我目前正在构建一个库项目,但我遇到了一些关于 XML 属性的问题。在库模块中,我创建了declare-styleable in attrs.xml
<resources>
<declare-styleable name="betterTextViewAttrs">
<attr name="typefaceAsset" format="string"/>
<attr name="scaleWithinBounds" format="boolean"/>
</declare-styleable>
我想在项目的示例布局中引用 attrs。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bettertv="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.virtualprodigy.bettertextviewsample.MainActivity">
<com.virtualprodigy.bettertextview.BetterTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
bettertv:typefaceAsset="dancing _script.ttf"
bettertv:scaleWithinBounds="false"
app:layout_constraintBottom_toBottomOf="@+id/activity_main"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
app:layout_constraintRight_toRightOf="@+id/activity_main"
app:layout_constraintTop_toTopOf="@+id/activity_main" />
但由于某种原因,xmlns:bettertv="http://schemas.android.com/apk/res-auto" 无法正常工作。编译时出现以下错误。
Error:(11) No resource identifier found for attribute 'typefaceAsset' in package 'com.virtualprodigy.bettertextviewsample'
可以在 GitHub 上找到完整的源代码。任何帮助表示赞赏。
【问题讨论】:
标签: android xml xml-namespaces android-library