编辑文字在Android Pie 9.0中不可编辑

时间:2019-03-18 22:16:33

标签: android android-layout android-edittext android-view android-keypad

大家好,                我在updateForm: FormGroup; ngOnInit() { this.onLoad(); this.initForm(); } onLoad(){ this.permissionservice.getCountrieswithPermission().subscribe((posts)=> { const mapped = Object.keys( posts['results']).map(key => ({type: key, value: posts['results'][key]})); this.actualPermission = mapped; this.currentPermission = mapped; }); } // form get f() { return this.updateForm.controls; } private initForm(){ // TO DO: make it dynamic this.updateForm = this.formBuilder.group({ leq1_1: [], leq1_2: [], leq1_3: [], ..... .... }); } 上遇到了问题。我已覆盖AppCompatEditText,并在键盘(AppCompatEditText)中添加了Enter按钮。可以在所有Android版本上正常运行,期望在9.0上运行。这是我班的代码

setImeOptions(EditorInfo.IME_ACTION_GO)

还有我的XML。

 public class EditTextWithGOButton extends AppCompatEditText {

    private EditTextAction editTextAction;

    public interface EditTextAction {
        void onGoButtonClicked(String text);
    }

    public void setEditTextAction(EditTextAction editTextAction) {
        this.editTextAction = editTextAction;

    }

    public EditTextWithGOButton(Context context) {
        super(context);
        changeImeOption();
    }

    public EditTextWithGOButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        changeImeOption();
    }

    public EditTextWithGOButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        changeImeOption();
    }

    private void changeImeOption() {
        this.setImeOptions(EditorInfo.IME_ACTION_GO);

    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                (keyCode == KeyEvent.KEYCODE_ENTER)) {
            if (editTextAction != null){

                editTextAction.onGoButtonClicked(getText().toString());

            }
        }
        // Returning false allows other listeners to react to the press.
        return false;

        // Handle all other keys in the default way
//        return super.onKeyDown(keyCode, event);
    }
}

我已经厌倦了手动设置聚焦能力。当我删除<com.app.common.views.EditTextWithGOButton android:id="@+id/edt_search_bar" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3.2" android:background="@drawable/search_edittext_rounded_corner_background" android:drawableRight="@android:drawable/ic_menu_search" android:drawableTint="@color/colorPrimary" android:hint="@string/search_your_activity" android:paddingRight="10dp" android:paddingLeft="10dp" android:maxLines="1" android:paddingTop="05dp" android:paddingBottom="05dp" android:textColorHint="@color/colorPrimary" /> this.setImeOptions(EditorInfo.IME_ACTION_GO);侦听器时,onKeyDown变为可编辑状态,但是键盘不会弹出。我也尝试过AppCompatEditText。但是问题仍然相同。 任何解决方案 ??

0 个答案:

没有答案