常用配置:
<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();
}
});