简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM