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 TextView
in 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>
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" />
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With