0
我需要實現一個EditText允許文本比屏幕尺寸更是在:Android的 - 多行的EditText wothout自動換行
android:inputType="textLongMessage"
而且還支持回車鍵爲:
android:inputType="textMultiLine"
嘗試覆蓋dispatchKeyEvent,但仍無法解決此問題。
<EditText
android:id="@+id/basicBatEdittext"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#000"
android:gravity="top"
android:scrollHorizontally="true"
android:hint="Hey there!\nHow is it going?"
android:inputType="textLongMessage"
android:padding="6dp"
android:textColor="#fff"
android:textColorHint="#fff"
android:textCursorDrawable="@null" />
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER || event.getKeyCode() == KeyEvent.ACTION_DOWN || event.getKeyCode() == KeyEvent.KEYCODE_NAVIGATE_NEXT) {
String temp = edittext.getText().toString() + "\n";
edittext.setText(temp);
return true;
}
return super.dispatchKeyEvent(event);
};
它只是將兩個空格添加到EditText。