我有一个代码来更改文本,如创建
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
Button btnbut = FindViewById<Button>(Resource.Id.btnbut);
TextView txtvw = FindViewById<TextView>(Resource.Id.txtView);
txtvw.Text = "Hello World";
btnbut.Text = "Hello WOrld";
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout1">
<TextView
android:layout_width="match_parent"
android:layout_height="47.5dp"
android:id="@+id/txtView"
android:layout_marginLeft="1.0dp"
android:layout_marginRight="0.0dp" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnbut" />
</LinearLayout>
当我使用模拟器运行并打开应用程序时,Text与main.axml上的define保持一致,而不是文本定义OnCreate
。