gpt4 book ai didi

android - TextView 不显示任何文本

转载 作者:行者123 更新时间:2023-12-03 23:36:48 26 4
gpt4 key购买 nike

我刚刚安装了 Android Studio 并在其中创建了一个项目,但是每当我在其中添加一个 TextView 时,它都没有显示任何内容,即使是 TextView已由 Android Studio 创建的未显示Activity.xml代码是

<?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:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="25dp">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="67dp"
tools:text="Hello World" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
tools:text="sdfsfsfsfs" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

tools:text="Hello World" />

</android.support.constraint.ConstraintLayout>

任何帮助,将不胜感激。

最佳答案

可能是一个迟到的答案,但只要它对某人有帮助。
您正在使用属性 tools:text为您的最后一个 TextView 。 tools 命名空间仅用于 android studio 中的布局预览。
要让 textview 在运行时显示某些内容,您必须使用 android 命名空间和 android:text像这样的属性(property):

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World" />
此外,只有第一个 textview 受到约束。尝试为剩余的电视添加约束。
而且,如果您的设计窗口没有显示任何文本而是显示空白屏幕,您可能需要更改设计窗口中的“预览主题”以匹配您的应用程序主题(例如: Material 主题、灯光、应用程序主题等)
The sixth button, which shows "Material Theme" right now

关于android - TextView 不显示任何文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52078056/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com