Android之Edittext详解

android:digits="1234567890.+-*/%\n()"

限制输入框中只能输入自己定义的这些字符串 如果输入其它将不予以显示

android:phoneNumber="true"

限制输入框中只能输入手机号码

android:password="true"

制输入框中输入的任何内容将以"*"符号来显示

android:hint="默认文字"

输入内容前默认显示在输入框中的文字

android:textColorHint="#FF0000"

设置文字内容颜色

android:enabled="false"

设置输入框不能被编辑

public class KeyBoardActivity extends Activity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.keyboard);

        EditText editText0 = (EditText)findViewById(R.id.txtTest0);

        editText0.setOnEditorActionListener(new OnEditorActionListener() {

            @Override

            public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {

                if (arg1 == EditorInfo.IME_ACTION_GO) {

                    Toast.makeText(KeyBoardActivity.this, "你点了软键盘'去往'按钮",

                            Toast.LENGTH_SHORT).show();

                }

                return false;

            }

        });

        EditText editText1 = (EditText)findViewById(R.id.txtTest1);

        editText1.setOnEditorActionListener(new OnEditorActionListener() {

            @Override

            public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {

                if (arg1 == EditorInfo.IME_ACTION_SEARCH) {

                    Toast.makeText(KeyBoardActivity.this, "你点了软键盘'搜索'按钮",

                            Toast.LENGTH_SHORT).show();

                }

                return false;

            }

        });

        EditText editText2 = (EditText)findViewById(R.id.txtTest2);

        editText2.setOnEditorActionListener(new OnEditorActionListener() {

            @Override

            public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {

                if (arg1 == EditorInfo.IME_ACTION_SEND) {

                    Toast.makeText(KeyBoardActivity.this, "你点了软键盘'发送'按钮",

                            Toast.LENGTH_SHORT).show();

                }

                return false;

            }

        });

        EditText editText3 = (EditText)findViewById(R.id.txtTest3);

        editText3.setOnEditorActionListener(new OnEditorActionListener() {

            @Override

            public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {

                if (arg1 == EditorInfo.IME_ACTION_NEXT) {

                    Toast.makeText(KeyBoardActivity.this, "你点了软键盘'下一个'按钮",

                            Toast.LENGTH_SHORT).show();

                }

                return false;

            }

        });

        EditText editText4 = (EditText)findViewById(R.id.txtTest4);

        editText4.setOnEditorActionListener(new OnEditorActionListener() {

            @Override

            public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {

                if (arg1 == EditorInfo.IME_ACTION_DONE) {

                    Toast.makeText(KeyBoardActivity.this, "你点了软键盘'完成'按钮",

                            Toast.LENGTH_SHORT).show();

                }

                return false;

            }

        });

        EditText editText5 = (EditText)findViewById(R.id.txtTest5);

        editText5.setOnEditorActionListener(new OnEditorActionListener() {

            @Override

            public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) {

                if (arg1 == EditorInfo.IME_ACTION_UNSPECIFIED) {

                    Toast.makeText(KeyBoardActivity.this, "你点了软键盘'未指定'按钮",

                            Toast.LENGTH_SHORT).show();

                }

                return false;

            }

        });

        super.onCreate(savedInstanceState);

    }

}

转载自: http://www.apkbus.com/android-13422-1-2.html

posted @ 2012-12-11 09:13  JD.Tang  阅读(553)  评论(0编辑  收藏  举报