Android Studio监听回车事件,捕获手机和扫描枪的Enter键的点击事件 package com.example.mynewtest;
Android Studio监听回车事件,捕获手机和扫描枪的Enter键的点击事件
package com.example.mynewtest;
import Android.content.Context;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Login extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Button button = (Button) findViewById(R.id.button);
EditText editText = (EditText) findViewById(R.id.edittext);
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_SEARCH) {
System.out.println("这里是监听扫码枪的回车事件");
return true;
}
if(event.geTKEyCode()==KeyEvent.KEYCODE_ENTER&&v.getText()!=null&& event.getAction() == KeyEvent.ACTION_DOWN){
System.out.println("这里是监听手机的回车事件");
}
return true;
}
});
}
}
--结束END--
本文标题: Android Studio中Edittext监听回车事件,捕获手机和扫描枪的Enter键的点击事件
本文链接: https://lsjlt.com/news/29580.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-01-21
2023-10-28
2023-10-28
2023-10-27
2023-10-27
2023-10-27
2023-10-27
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0