我想在我的项目中使用自动调整文本,当我使用android:
前缀时,AS不会抱怨。但由于我想要向下兼容,我使用app前缀。它在应用程序运行时有效,但xml预览错误,我在以Unexpected namespace prefix "app" found for tag TextView
开头的每一行都收到警告app:
。
我可以简单地忽略它吗?
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.exampleapp">
<TextView
android:id="@+id/text_view_auto_size"
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Hello World!"
app:autoSizeTextType="uniform"
app:autoSizePresetSizes="@array/autosize_text_sizes"
app:autoSizeMaxTextSize="200dp"
app:autoSizeMinTextSize="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:7)
您必须使用AppCompatTextView。由于您正在使用AppCompat功能(通过访问app:*
来执行此操作(请注意,该特定命名空间添加了自定义属性,但同样位于应用程序命名空间中的集成属性通常是AppCompat))您必须使用AppCompatTextView,因为它支持这些属性
<android.support.v7.widget.AppCompatTextView
android:id="@+id/text_view_auto_size"
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Hello World!"
app:autoSizeTextType="uniform"
app:autoSizePresetSizes="@array/autosize_text_sizes"
app:autoSizeMaxTextSize="200dp"
app:autoSizeMinTextSize="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
答案 1 :(得分:3)
正如评论中提到的那样,您只需要在编写自定义视图时手动使用AppCompat类:docs
因此,无需在XML中使用AppCompatTextView而不是TextView。
只需在您的基本应用程序文件夹中添加lint.xml
文件,并将以下行放入其中即可忽略“ MissingPrefix”错误:
<?xml version="1.0" encoding="utf-8"?>
<lint>
<issue id="MissingPrefix" severity="ignore" />
</lint>
如果您使用Calligraphy,例如:https://github.com/chrisjenx/Calligraphy/issues/221
,它也将很有用。