在这里,我使用以下代码创建自定义编辑文本。现在我面临一个奇怪的问题,当我尝试将 IME 选项覆盖输入按钮并将其功能更改为发送时,我无法实现该选项。有人请帮我解决这个问题。
public class CustomEditText extends EditText {
public CustomEditText (Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public CustomEditText (Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public CustomEditText (Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
System.out.println("kkeeueueueehu");
if (keyCode == KeyEvent.KEYCODE_BACK
&& event.getAction() == KeyEvent.ACTION_UP) {
li_bootm.setVisibility(View.GONE);
// Do your thing here
return false;
}
return false;
}
}
//here is how i use it in my fragment
private CustomEditText messageEditText;
private LinearLayout liedittext;
在我的 onCreateView
liedittext = (LinearLayout) v.findViewById(R.id.liedittext);
messageEditText = new NoImeEditText(getActivity());
liedittext.addView(messageEditText);
messageEditText.setBackgroundColor(Color.TRANSPARENT);
messageEditText.setHint("enter_message");
messageEditText.setSingleLine(false);
messageEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
// TODO Auto-generated method stub
// InputMethodManager imm = (InputMethodManager) getActivity()
// .getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.hideSoftInputFromWindow(messageEditText.getWindowToken(),
// 0);
doSave();
li_bootm.setVisibility(View.GONE);
return false;
}
});
当我把
messageEditText.setSingleLine(false);
IME 选项不可用,但当
messageEditText.setSingleLine(true);
IME 选项可用,但我的编辑文本中需要多行
这是我的线性布局
<LinearLayout
android:id="@+id/liedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>