在这里,我使用以下代码创建自定义edittext。现在我面临一个奇怪的问题,当我尝试将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);
I IME选项不可用,但
时messageEditText.setSingleLine(true);
可以使用IME选项,但我的edittext需要多行
这是我的线性布局
<LinearLayout
android:id="@+id/liedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>