Android Studio preview goes blank when I add <com.google.android.material.textfield.TextInputEditText>

huangapple go评论64阅读模式
英文:

Android Studio preview goes blank when I add <com.google.android.material.textfield.TextInputEditText>

问题

在我开发的任何Android应用中,我个人更喜欢com.google.android.material.textfield.TextInputEditText视图,而不是普通的EditText,在我看来,它在各个方面看起来更漂亮。

然而,使用com.google.android.material.textfield.TextInputEditText的问题是,在Android Studio中的预览会变为空白。当你只能通过编译并在设备上运行实际应用来查看UI时,设计UI变得困难。

以下是我的fragment_world.xml文件的部分内容:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    tools:context=&quot;.WorldFragment&quot;&gt;

    &lt;com.google.android.material.textfield.TextInputLayout
        android:id=&quot;@+id/textField&quot;
        android:layout_width=&quot;0dp&quot;
        android:layout_height=&quot;wrap_content&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintEnd_toEndOf=&quot;parent&quot;&gt;

        &lt;com.google.android.material.textfield.TextInputEditText
            android:id=&quot;@+id/editText&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:hint=&quot;Hello, world!&quot; /&gt;

    &lt;/com.google.android.material.textfield.TextInputLayout&gt;

&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

如您所见,这里没有发生任何异常情况。在我将com.google.android.material.textfield.TextInputEditText视图添加到布局之前,预览正常显示。现在,预览变为空白。如果我切换到不同的选项卡,然后切换回来,我可以看到布局中每个视图的轮廓,但它迅速恢复到之前的空白状态。

我尝试创建一个全新的项目,其中只包含这个布局:

&lt;com.google.android.material.textfield.TextInputLayout
    android:id=&quot;@+id/textField&quot;
    android:layout_width=&quot;0dp&quot;
    android:layout_height=&quot;wrap_content&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;&gt;

    &lt;com.google.android.material.textfield.TextInputEditText
        android:id=&quot;@+id/editText&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:hint=&quot;Hello, world!&quot; /&gt;

&lt;/com.google.android.material.textfield.TextInputLayout&gt;

这也没有起作用,发生了完全相同的情况。

英文:

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:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    tools:context=&quot;.WorldFragment&quot;&gt;

    &lt;com.google.android.material.textfield.TextInputLayout
        android:id=&quot;@+id/textField&quot;
        android:layout_width=&quot;0dp&quot;
        android:layout_height=&quot;wrap_content&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintEnd_toEndOf=&quot;parent&quot;&gt;

        &lt;com.google.android.material.textfield.TextInputEditText
            android:id=&quot;@+id/editText&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;wrap_content&quot;
            android:hint=&quot;Hello, world!&quot; /&gt;

    &lt;/com.google.android.material.textfield.TextInputLayout&gt;

&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

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:

&lt;com.google.android.material.textfield.TextInputLayout
    android:id=&quot;@+id/textField&quot;
    android:layout_width=&quot;0dp&quot;
    android:layout_height=&quot;wrap_content&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;&gt;

    &lt;com.google.android.material.textfield.TextInputEditText
        android:id=&quot;@+id/editText&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot;
        android:hint=&quot;Hello, world!&quot; /&gt;

&lt;/com.google.android.material.textfield.TextInputLayout&gt;

That did not work, the same exact thing happened.

答案1

得分: 3

这实际上是Android Studio本身的问题。在尝试相同的设置时,Canary 6版本完全正常。

英文:

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

答案2

得分: 1

我遇到了相同的问题,问题始于

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

目前,我已将版本更改为

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

它能够正常工作,根据评论中的信息,问题出在Android Studio,所以我只需等待修复。

英文:

Have the same problem, the issue starts from

implementation &#39;com.google.android.material:material:1.8.0&#39;

for now, I`ve changed the version to

implementation &#39;com.google.android.material:material:1.7.0&#39;

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

huangapple
  • 本文由 发表于 2023年2月19日 10:23:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75497624.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定