[英]Displaying text using textView() Android
Unsure of how to display text in the xml file, i have code written to output text in the java file but nothing happens when the application is run不确定如何在 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"/>
Use this:用这个:
<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" />
And then setText
然后设置setText
为什么要在 xml 和 java 中设置两次文本,只需添加一次为:但是无论尝试提供什么:字体大小和布局的重力(中心),以编程方式或在 xml 中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.