英文:
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
文件的部分内容:
<?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>
如您所见,这里没有发生任何异常情况。在我将com.google.android.material.textfield.TextInputEditText
视图添加到布局之前,预览正常显示。现在,预览变为空白。如果我切换到不同的选项卡,然后切换回来,我可以看到布局中每个视图的轮廓,但它迅速恢复到之前的空白状态。
我尝试创建一个全新的项目,其中只包含这个布局:
<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>
这也没有起作用,发生了完全相同的情况。
英文:
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.
答案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 '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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论