gpt4 book ai didi

java - 更改 "imeOptions"(Android) 的行为

转载 作者:行者123 更新时间:2023-12-01 10:24:42 27 4
gpt4 key购买 nike

伙计们,这就是我现在的问题。

我有下一个 TextView 和 EditText

activity_profile.xml

<TextView
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/done"
android:id="@+id/done_profile_btn"
android:textColor="@color/white"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:id="@+id/input_profile_swift"
android:hint="@string/swift"
android:inputType="textCapCharacters"
android:textColor="@color/colorPrimaryDark"
android:layout_marginBottom="22dp"
android:maxLines="1"
android:imeOptions="actionDone"/>

我想更改按键盘上的“完成”按钮对 EditText 执行的操作,以便执行与 TextView 相同的操作,后者执行以下操作:

ProfileActivity.java

done_btn = (TextView) findViewById(R.id.done_profile_btn);
swift = (EditText)findViewById(R.id.input_profile_swift);
done_btn.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
//saveChanges();
//finish();
Toast.makeText(getApplicationContext(), "Your changes have been saved", Toast.LENGTH_SHORT).show();
}
});
...

所以...我希望两者(按键盘上的“完成”并按 TextView)执行相同的操作。

知道如何做到这一点吗?非常感谢。

最佳答案

您也可以使用这个(设置在 EditText 上执行操作时调用的特殊监听器),它适用于 DONE 和 RETURN:

swift.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
//saveChanges();
//finish();
Toast.makeText(getApplicationContext(), "Your changes have been saved", Toast.LENGTH_SHORT).show();
}
return false;
}
});

希望对你有帮助!

关于java - 更改 "imeOptions"(Android) 的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35405686/

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