後來才知道原來是 Text Fields 分類內的 Plain Text 控件
官網上看見兩個範例,整合在一起練習
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/txtInput"/> <TextView android:text="Text" android:layout_width="match_parent" android:layout_height="47.5dp" android:id="@+id/txtResult" /> </LinearLayout>
namespace EditTextPractice { [Activity(Label = "EditTextPractice", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); EditText txtInput = FindViewById<EditText>(Resource.Id.txtInput); TextView txtResult = FindViewById<TextView>(Resource.Id.txtResult); txtInput.TextChanged += (sender, e) => { txtResult.Text = e.Text.ToString();}; txtInput.KeyPress += (sender, e) => { e.Handled = false; if (e.KeyCode == Keycode.Enter) Toast.MakeText(this, txtInput.Text, ToastLength.Short).Show(); e.Handled = true; }; } } }
沒有留言:
張貼留言