【问题标题】:Displaying text using textView() Android使用 textView() Android 显示文本
【发布时间】:2015-11-24 18:41:47
【问题描述】:

不确定如何在 xml 文件中显示文本,我已将代码写入 java 文件中的输出文本,但运行应用程序时没有任何反应

TextView tv = (TextView) findViewById(R.id.my_text_view);
tv.setText("Welcome to the Dungeon");

*

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/my_text_view"
android:text="@string/my_text_view"/>

【问题讨论】:

标签: java android xml android-studio


【解决方案1】:

使用这个:

<TextView android:id="@+id/my_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Example"
    android:layout_gravity="center"
    android:textColor="#656565"
    android:textSize="20dp" />

然后setText

【讨论】:

    【解决方案2】:

    为什么要在xml和java中设置两次文本,只需添加一次即可: 但无论尝试提供什么:字体大小和布局的重心(中心),无论是编程方式还是在 xml 中

    【讨论】:

    • 我在我的 mainactivity.java 中有一个加载 system.out.println 语句,我试图显示
    • 好的,那你遇到什么问题,用字符串格式打印出来,使用tv.getText()......一些。
    • 使用 toString() 方法?
    • 是的,你很清楚,必须转换为字符串,因此,我有.....代替那个
    猜你喜欢
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 2014-05-15
    • 2016-01-14
    • 2012-09-03
    • 2011-12-14
    相关资源
    最近更新 更多