首页 > 系统 > Android > 正文

[Android新手学习笔记12]-UI控件之EditText

2019-11-09 16:07:25
字体:
来源:转载
供稿:网友

常用配置:

<EditText        android:id="@+id/edit_text"        android:hint="Type something here"        android:maxLines="2"

       android:layout_width="match_parent"

       android:layout_height="wrap_content" />

android:hint:提示文字。

android:maxLinex:最多显示行数。

获取文字信息:

Button button = (Button) findViewById(R.id.button);
final EditText editText = (EditText) findViewById(R.id.edit_text);button.setOnClickListener(new View.OnClickListener() {    @Override    public void onClick(View v) {    String inputText = editText.getText().toString();    Toast.makeText(MainActivity.this, inputText, Toast.LENGTH_SHORT).show();        }    });
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表