所以我的Oneplus 3t上有一个问题,即输入键创建了一个新的行并且实际上没有动作,但在三星手机上它工作正常。这是EditText
<EditText
android:id="@+id/section"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="30dp"
android:layout_toEndOf="@+id/nav_button"
android:layout_toRightOf="@+id/nav_button"
android:background="@android:color/transparent"
android:clickable="false"
android:ems="10"
android:focusable="false"
android:gravity="left"
android:inputType="textMultiLine|textNoSuggestions"
android:maxHeight="140dp"
android:scrollbars="vertical"
android:text="@string/section"
android:textColor="@color/textColor"
android:textSize="20sp" />
这就是我处理行动的方式
mSearch.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
switch (i) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
unReadySeach(section, mSearch, search, mSearch.getText().toString(), mNavButton, backArrow);
gridView.setAdapter(new QuoteImageAdapater(getApplicationContext(), reader.getSearchData(mSearch.getText().toString()), section));
searched = true;
return true;
}
}
return false;
}
});
同样在像素2上的虚拟设备中,当我按下键盘上的回车键时,它会创建一个新行,但是当我按下我自己键盘上的输入键时,它确实有效。
编辑:我通过将EditText更改为此来修复它
<EditText
android:id="@+id/searchText"
android:layout_width="230dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/section"
android:layout_alignBottom="@+id/section"
android:layout_alignStart="@+id/section"
android:background="@drawable/underline"
android:ems="10"
android:hint="Search"
android:imeOptions="actionSearch"
android:inputType="textNoSuggestions|text"
android:maxHeight="140dp"
android:textColor="@color/textColor"
android:textColorHint="@color/textHint"
android:textCursorDrawable="@null"
android:textSize="20sp"
android:visibility="invisible" />
尝试这个,因为你使用过的解决方案,不保证软键。
第一解决方案
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/search_hint"
android:inputType="text"
android:imeOptions="actionSend" />
EditText editText = (EditText) findViewById(R.id.search);
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = false;
if (actionId == EditorInfo.IME_ACTION_SEND) {
sendMessage();
handled = true;
}
return handled;
}
});
二解决方案
mSearch.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
unReadySeach(section, mSearch, search, mSearch.getText().toString(), mNavButton, backArrow);
gridView.setAdapter(new QuoteImageAdapater(getApplicationContext(), reader.getSearchData(mSearch.getText().toString()), section));
searched = true;
return true;
}
return false;
}
});