自动调整TextView - 我可以忽略意外的名称前缀警告吗?

Flo*_*her 5 android textview

我想在我的项目中使用自动调整文本,当我使用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>
Run Code Online (Sandbox Code Playgroud)

Zoe*_*Zoe 7

您必须使用AppCompatTextView.由于您正在使用AppCompat功能(通过访问app:*(请注意该特定命名空间添加自定义属性,但也在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" />
Run Code Online (Sandbox Code Playgroud)

  • 嘿,我刚刚在AppCompatTextView的文档中发现了一些有趣的东西:"当你在布局中使用TextView并且appcompat提供顶级活动/对话框时,这将自动使用.你应该只需要在编写时手动使用这个类自定义视图." https://developer.android.com/reference/android/support/v7/widget/AppCompatTextView.html所以这就是它的工作原理 - 我的Activity是一个AppCompatActivity (3认同)