![](/img/trans.png)
[英]click a button multiple times to run the same function, java android studio
[英]Android Studio: Button same function as Keycode Enter
我已經為android制作了一個webbrowser應用程序(minSdkVersion 21)它工作正常,但是鍵盤和按鈕有點問題。
在這里你可以看到應用程序有一個按鈕,當我點擊GO它加載一個頁面。 但是當我點擊進入我的鍵盤時,它什么也沒做。
我嘗試過以下方法:
在我的activity_main.xml
<Button
android:id="@+id/button"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:imeOptions="actionGo"
android:layout_centerVertical="true"
android:text="Go"/>
我認為到目前為止我的activity_main.xml
沒有問題
在我的MainActivity.java
我有:
Button button;
button = (Button) findViewById(R.id.button);
button.setImeActionLabel("", KeyEvent.KEYCODE_ENTER);
webView.loadUrl("");
return true;
當我點擊鍵盤上的Enter鍵時,我希望功能與我的按鈕“GO”相同(需要加載頁面)
粘貼此代碼。 這里編輯文本是editText,您正在接受輸入。
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((actionId == EditorInfo.IME_ACTION_DONE)) {
//Your Action as go button
}
return false;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.