後來才知道原來是 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;
};
}
}
}
![[X.Andriod] EditText-1](https://c7.staticflickr.com/8/7713/27176174814_956be47974_m.jpg)
![[X.Andriod] EditText-3](https://c8.staticflickr.com/8/7346/27713272151_88dfa4ef07_z.jpg)
![[X.Andriod] EditText-2](https://c5.staticflickr.com/8/7202/27176174844_c410fa309f_b.jpg)
沒有留言:
張貼留言