skip to Main Content

In any Android app that I have developed, I personally prefer the com.google.android.material.textfield.TextInputEditText view, rather than the plain EditText, just as, in my opinion, it looks much nicer in any and every way possible.

The problem, though, with using com.google.android.material.textfield.TextInputEditText, the preview in Android Studio goes blank. It is difficult to design UI when you cannot preview it except by compiling, and running the actual app on the device.

Here is my fragment_world.xml file:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".WorldFragment">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/textField"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/editText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Hello, world!" />

    </com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

As you can see, nothing out of the ordinary is going on here. The preview showed just fine before I added the com.google.android.material.textfield.TextInputEditText view into the layout. Now, the preview goes blank. If I switch to a different tab, and switch back, I can see the outlines of each view in the layout, but it quickly reverts back to its previous, blank state.

I have attempted to create a new, clean project, with nothing in it except this layout here:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textField"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Hello, world!" />

</com.google.android.material.textfield.TextInputLayout>

That did not work, the same exact thing happened.

3

Answers


  1. Chosen as BEST ANSWER

    It is actually an issue with Android Studio itself. Upon trying the same setup in the Canary 6 version, it works perfectly fine.


  2. Make sure that your app theme should be

    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

    currently, it should be

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    I think this should help if all the dependencies are set.

    Happy Coding 🙂

    Login or Signup to reply.
  3. Have the same problem, the issue starts from

    implementation 'com.google.android.material:material:1.8.0'
    

    for now, I`ve changed the version to

    implementation 'com.google.android.material:material:1.7.0'
    

    and it works, as I see in the comments the problem is in the Android Studio, so just waiting for the fix

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search