gpt4 book ai didi

android - InputType 对自定义 EditText 没有影响

转载 作者:行者123 更新时间:2023-11-30 00:04:26 24 4
gpt4 key购买 nike

我创建了这个扩展自 AppCompatEditText 的自定义 View :

    public class NoteEditText extends AppCompatEditText {

// INTERFACES ----------------------------------------------------------------------------------------------------
public interface OnKeyPreImeListener {
void onKeyPreIme(int keyCode, KeyEvent event);
}


// ATTRIBUTES ----------------------------------------------------------------------------------------------------
private MovementMethod movementMethod;
private KeyListener keyListener;
private OnKeyPreImeListener onKeyPreImeListener;


// CONSTRUCTORS ----------------------------------------------------------------------------------------------------
public NoteEditText(Context context) {
super(context);

this.movementMethod = this.getMovementMethod();
this.keyListener = this.getKeyListener();
}

public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs);

this.movementMethod = this.getMovementMethod();
this.keyListener = this.getKeyListener();
}

public NoteEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);

this.movementMethod = this.getMovementMethod();
this.keyListener = this.getKeyListener();
}


// SETTERS ----------------------------------------------------------------------------------------------------
public void setOnKeyPreImeListener(OnKeyPreImeListener onKeyPreImeListener) {
this.onKeyPreImeListener = onKeyPreImeListener;
}


// METHODS ----------------------------------------------------------------------------------------------------
public void enable() {
this.setMovementMethod(this.movementMethod);
this.setKeyListener(this.keyListener);
this.setFocusableInTouchMode(true);
this.setImeOptions(EditorInfo.IME_ACTION_DONE);
this.setRawInputType(InputType.TYPE_CLASS_TEXT);
}

public void disable() {
this.setMovementMethod(null);
this.setKeyListener(null);
}

public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (this.onKeyPreImeListener != null)
this.onKeyPreImeListener.onKeyPreIme(keyCode, event);

return true;
}

}

我这样调用它:

    <com.company.adapters.items.NoteEditText
android:id="@+id/note"
style="@style/AppTheme.SubItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_margin_xs"
android:gravity="center_vertical"
android:hint=""
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences|textNoSuggestions"
android:minHeight="@dimen/content_subitem_height"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/note_icon"
app:layout_constraintTop_toBottomOf="@+id/name" />

它运行良好,除了“textMultiLine|textCapSentences|textNoSuggestions”输入类型。 “textCapSentences”和“textNoSuggestions”均未应用,但“textMultiLine”正在运行。

如果我使用完全相同的配置但使用原始的 EditText View ,则所有 inputTypes 都有效......非常奇怪。

最佳答案

    this.setRawInputType(InputType.TYPE_CLASS_TEXT);

来自您的启用功能。这是覆盖输入类型。

关于android - InputType 对自定义 EditText 没有影响,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49264388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com