我正在使用多行EditText。键入完成并触摸另一视图后,我希望editText仅显示一行。怎么做?
<EditText
android:id="@+id/descriptionfield"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
/>
您可以将setOnFocusChangeListener
设置为如下所示的编辑文本
descriptionfield.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
descriptionfield.setSingleLine(false);
} else {
descriptionfield.setSingleLine(true);
}
}
});
如果edittext具有焦点,则setSingleLine
至false
否则setSingleLine
至true
希望对您有帮助