Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autosizing TextView - can I ignore the unexpected name prefix warning?

I want to use autosizing text in my project and AS doesn't complain when i use the android: prefix. But since I want downwards compatibility, I use the app prefix. It works when the app is running, but the xml preview is buggy and I get the warning Unexpected namespace prefix "app" found for tag TextViewin every line that starts with app:.

Can I simply ignore that?

<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>
like image 862
Florian Walther Avatar asked Jan 11 '18 18:01

Florian Walther


2 Answers

You have to use an AppCompatTextView instead. Since you're using AppCompat features (which you do by accessing app:* (note that that particular namespace adds custom attributes, but the integrated ones that also are in the app namespace are usually AppCompat)) you have to use the AppCompatTextView as it supports these attributes

<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" />
like image 167
Zoe stands with Ukraine Avatar answered Oct 20 '22 14:10

Zoe stands with Ukraine


As it was mentioned in comments, You should only need to manually use AppCompat classes when writing custom views: docs

So, there is no need to use AppCompatTextView instead of TextView inside your xml.

Simply, in your base application folder add lint.xml file and put the following lines into it to ignore "MissingPrefix" errors:

<?xml version="1.0" encoding="utf-8"?>
<lint>
    <issue id="MissingPrefix" severity="ignore" />
</lint>

It will be also useful, if you use Calligraphy for example: https://github.com/chrisjenx/Calligraphy/issues/221

like image 31
repitch Avatar answered Oct 20 '22 15:10

repitch