簡體   English   中英

Android Studio:按鈕功能與Keycode Enter相同

[英]Android Studio: Button same function as Keycode Enter

我已經為android制作了一個webbrowser應用程序(minSdkVersion 21)它工作正常,但是鍵盤和按鈕有點問題。

在這里你可以看到應用程序有一個按鈕,當我點擊GO它加載一個頁面。 但是當我點擊進入我的鍵盤時,它什么也沒做。

在此輸入圖像描述

我嘗試過以下方法:

  • KeyEvent.KEYCODE_ENTER
  • 使用loadURL

在我的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM