Upon opening Android Studio today, I was greeted with a surprise – I could not see the preview of my layout:
I thought it would just be a simple fix of:
- Reloading the designer
- Cleaning and building the project
- Invalidating caches and restarting
Although none of these have fixed the issue.
I have also went through other people having render issues and have tried various solutions although I’m still encountering the problem.
The strange thing is, whenever I remove the TextInputLayout
widgets from my layout, the render problem disappears:
(Below is one of the layouts which is causing the problem.)
<?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"
android:id="@+id/fragmentNewCanvas_rootLayout"
tools:context=".fragments.newcanvas.NewCanvasFragment">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/fragmentNewCanvas_projectTitleTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:hint="@string/fragmentNewCanvas_project_name_str"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/fragmentNewCanvas_projectTitleTextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/fragmentNewCanvas_spanCountTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:hint="@string/fragmentNewCanvas_span_count_str"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fragmentNewCanvas_projectTitleTextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/fragmentNewCanvas_spanCountTextInputEditText"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/fragmentNewCanvas_doneButton"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:text="@string/str_button_done"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is a gif demonstrating the problem:
Layouts which do not contain a TextInputLayout
render fine, but those that do are causing problems.
Stacktrace:
java.lang.IllegalArgumentException: weight is out of range of [0, 1000] (too low)
at com.android.internal.util.Preconditions.checkArgumentInRange(Preconditions.java:527)
at android.graphics.Typeface.create_Original(Typeface.java:979)
at android.graphics.Typeface_Delegate.create(Typeface_Delegate.java:123)
at android.graphics.Typeface.create(Typeface.java:979)
at com.google.android.material.internal.CollapsingTextHelper.maybeCloneWithAdjustment(CollapsingTextHelper.java:532)
at com.google.android.material.internal.CollapsingTextHelper.setCollapsedTypefaceInternal(CollapsingTextHelper.java:475)
at com.google.android.material.internal.CollapsingTextHelper.setTypefaces(CollapsingTextHelper.java:459)
at com.google.android.material.textfield.TextInputLayout.setEditText(TextInputLayout.java:1467)
at com.google.android.material.textfield.TextInputLayout.addView(TextInputLayout.java:888)
at android.view.ViewGroup.addView(ViewGroup.java:5048)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1131)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1130)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:361)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:727)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:883)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
If anyone has a solution it would be greatly appreciated.
3
Answers
Found a temporary workaround:
Change theme from
Material3
toMaterialComponents
Will be waiting for a bugfix.
change
implementation ‘com.google.android.material:material:x.x.x-alpha’
to
implementation ‘com.google.android.material:material:1.5.0’
Ran into the same issue today using TextInputLayout, upgrading to
com.google.android.material:material:1.6.0-alpha03
resolved it for me.