答案 0 :(得分:1)
您可以使用Key事件。在edittext上设置setOnKeyListener并执行以下操作:
if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)
//Load url from EditText
答案 1 :(得分:1)
尝试实施OnEditorActionListener界面。例如:
// Reference the edit text view.
EditText theEditText = (EditText) findViewById(R.id.theEditText);
// Set editor action listener.
theEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_NULL) { // Enter key was pressed.
// Open link from url.
}
// Return true to prevent the edit text from adding a newline from the enter press.
return false; // Allow the event to propagate, Return true to consume the event.
}
});
如果按下回车键,actionId
将等于EditorInfo.IME_NULL
。
希望这有帮助。