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>
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
Related
i have error with EditText is "render problem" in design in android when i drag and drop "Plain Text" from Palette to frame design. But when i run app, app run and show normally in genymotion.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.122" />
<EditText
android:id="#+id/editTextTextPersonName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="92dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
thank you!
i solved this by change rendering engine (below the message Rendering problem). Sry. forgot to take a screenshot :P
Best way is to let android studio instruct you what could be possibly done a manner; efficient & standardized for developer by pressing alt+enter or following tip icon & applying the changes.
One thing you need to always remember is that "when you are using drag and drop feature in the android studio you need to extract string resources for every component
see this image of my code
In this code, the text view type is not specified in most cases like you there is an error for Hardcoded string. try to use ALT+Enter for specifically required operation on this particular component.
I'm trying to make some of my views invisibe. Here's the XML code:
<?xml version="1.0" encoding="utf-8"?>
<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=".MainActivity">
<Button
android:text="See More Like This"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/recommender"
tools:visibility="invisible"
android:layout_marginEnd="24dp" android:layout_marginRight="24dp" android:layout_marginBottom="20dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toTopOf="#+id/imageView"/>
<TextView
android:text="https://www.google.com"
android:layout_width="169dp"
android:layout_height="50dp"
android:autoLink="web"
android:linksClickable="true"
android:id="#+id/urlDisplay"
tools:visibility="invisible"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="24dp" android:layout_marginTop="101dp" android:layout_marginStart="24dp"/>
<TextView
android:text="TextView"
android:layout_width="0dp"
android:layout_height="59dp"
android:id="#+id/comicTitle" tools:visibility="invisible"
android:layout_marginTop="21dp" android:layout_marginBottom="21dp" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#+id/urlDisplay" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" android:layout_marginLeft="40dp"
android:layout_marginStart="40dp" android:layout_marginEnd="40dp" android:layout_marginRight="40dp"/>
</android.support.constraint.ConstraintLayout>
There is no kotlin code except for the boilerplate. When I start up the app, all of my views are visible. I don't understand how this is happening, given that I've explicitly set them to be invisible in xml.
How can I make them invisible?
Read Tools attributes reference
Android Studio supports a variety of XML attributes in the tools
namespace that enable design-time features (such as which layout to
show in a fragment) or compile-time behaviors (such as which shrinking
mode to apply to your XML resources). When you build your app, the
build tools remove these attributes so there is no effect on your APK
size or runtime behavior.
You should use android:visibility="invisible" instead of tools:visibility="invisible"
As you are using tools
tools:visibility="invisible"
Just replace the tools with the android it start working fine
android:visibility="invisible"
You have used tools:visibility="invisible"
use android:visibility="invisible" to make your view invisible.
In your xml you have set the tools:visibility="invisible" This is basically tools namespace supported in Android Studio
Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features.
When you build your app, the build tools remove these attributes so there is no effect on your APK size or run-time behavior. Hence when you run the app there is no effect of these attributes.
You can read more about tools attributes in official android dev docs
As suggested in comments you should instead set android:visibility="invisible"
I'm trying to use TextViewCompat on my app to support older android versions according this article from Android Documentation.
But I'm facing this waring on Android Studio:
Element TextViewCompat is not allowed here
This inspection highlights unallowed XML tags in Android resource files and AndroidManifest.xml
What am I doing wrong?
<?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"
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.841"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.87" />
<TextViewCompat
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:textSize="120sp"
android:text="10 min"
app:layout_constraintBottom_toTopOf="#+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Use android.support.v7.widget.TextViewCompat or android.support.v7.widget.AppCompatTextView
You don't need to do this to take advantage of AppCompatTextView, as per the documentation:
This will automatically be used when you use TextView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.
Basically, when you build your app, appcompat swaps out instances of various UI widgets in XML for the Compat version. As long as you aren't extending a widget, you don't need to worry about this behavior (and you'll get a lint warning telling you what to do if you do want to extend widgets).
You only need TextViewCompat if you try to manipulate the auto-sizing APIs programmatically from Java/Kotlin. This is done by finding the view as a TextView, and then using static methods on TextViewCompat:
TextView textView = findViewById(R.id.textView);
TextViewCompat.setAutoSizeTextTypeWithDefaults(textview, myTextSizeType);
I'm trying to build a simple android app in Android Studio 2.3.2, but I'm getting the following error for component I add to the app: "No resource identifier found for attribute 'layout_constraintBottom' in package 'com..."
I researched this problem and found that some people are getting a similar error. However, the answers are suggesting to add "compile 'com.android.support.constraint:constraint-layout:1.0.2'" to the gradle.build file. When I looked there, the line is already in place.
Here is a snippet of my code:
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_menu"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.nmeneses.scorekeeper.MainMenu"
tools:showIn="#layout/activity_main_menu">
<Button
android:id="#+id/button3"
android:layout_width="128dp"
android:layout_height="79dp"
android:layout_marginBottom="50dp"
android:layout_marginLeft="39dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="Teams"
android:textSize="23dp"
app:layout_constraintBottom="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.066"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
Any help would be greatly appreciated. If you need more info, please let me know.
AFAIK there is no attribute layout_constraintBottom in ConstraintLayout. There is layout_constraintBottom_toTopOf and layout_constraintBottom_toBottomOf.
I suggest that you use the following line instead:
app:layout_constraintBottom_toBottomOf="parent"
I'm trying to centre two textviews vertically using constraint layout chains. I know I can wrap the text layouts in a linear layout but I wanted to try out the new chain feature. When I build my project though I get an error, Error:(28, 50) No resource found that matches the given name (at 'layout_constraintBottom_toTopOf' with value '#id/item_school_location').
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="72dp">
<ImageView
android:id="#+id/item_school_logo"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:contentDescription="#string/item_school_logo_description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />
<TextView
android:id="#+id/item_school_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="72dp"
android:maxLines="1"
android:textAppearance="#style/TextAppearance.AppCompat.Light.SearchResult.Subtitle"
app:layout_constraintBottom_toTopOf="#id/item_school_location"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5"
app:layout_constraintVertical_chainPacked="true" />
<TextView
android:id="#+id/item_school_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="72dp"
android:maxLines="1"
android:textAppearance="#style/TextAppearance.AppCompat.Small"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/item_school_name" />
</android.support.constraint.ConstraintLayout>
</layout>
Anyone know what's causing this error?
app:layout_constraintLeft_toLeftOf="parent"
Maybe I'm not completely up to date, but I think the value shouldn't be "parent" - it should be a view ID (in the format of "#+id/some_id").
Give your constraint layout an id and then try using that instead of parent.
Edit: I guess I am out of date on this? Because I just read that again, and your error seems like this line:
layout_constraintBottom_toTopOf="#id/item_school_location"
is missing the + after # - as in it should be
layout_constraintBottom_toTopOf="#+id/item_school_location"
I think the
No resource found that matches the given name
error is due to the fact that you are referencing the id of an element (item_school_location) that is declared after the element referencing it (item_school_name).
In this case, it would help if you declare the ids of your related elements in a separate ids.xml file (check this: https://stackoverflow.com/a/12247971)