how to add Go button in android SoftKeyBoard and its functionality?

前端 未结 4 750
渐次进展
渐次进展 2021-02-06 04:26

i want to put \"Go\" button in android appliation softkeyboard

for search and other related scenarios can any one guide me how to achieve this? with example.

any

相关标签:
4条回答
  • 2021-02-06 05:08

    I am doing same this for "send":

    Use this class in your layout :

    public class ActionEditText extends EditText { public ActionEditText(Context context) { super(context); }

    public ActionEditText(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
    
    public ActionEditText(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }
    
    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs)
    {
        InputConnection conn = super.onCreateInputConnection(outAttrs);
        outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION;
        return conn;
    }
    

    }

    In xml:

    <com.test.custom.ActionEditText
                android:id="@+id/postED"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@android:color/transparent"
                android:gravity="top|left"
                android:hint="@string/msg_type_message_here"
                android:imeOptions="actionSend"
                android:inputType="textMultiLine"
                android:maxLines="5"
                android:padding="5dip"
                android:scrollbarAlwaysDrawVerticalTrack="true"
                android:textColor="@color/white"
                android:textSize="20sp" />
    
    0 讨论(0)
  • 2021-02-06 05:11

    finally i used...

    EditText SearchEditText =(EditText)findViewById(R.id.txtMapSearch); 
    SearchEditText.setOnEditorActionListener(new OnEditorActionListener(){  
    
        @Override 
        public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2) { 
            if(arg1 == EditorInfo.IME_ACTION_SEARCH)  
            { 
                // search pressed and perform your functionality.
            }
            return false; 
        } 
    
    }); 
    
    0 讨论(0)
  • 2021-02-06 05:14

    If your question is that you have an EditText or editable TextView, and you want the action right button on the softkeyboard to read "Go" then add this attribute to your EditText/TextView

    android:imeActionLabel="actionGo"
    

    note that it will also have to be a single line TextView as otherwise the action button will be a carriage return selector (an arrow).

    android:singleLine="true" 
    
    0 讨论(0)
  • 2021-02-06 05:21

    I used

    android:imeOptions="actionGo" 
    

    and to handle go action I ma using

    etSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_GO || actionId == EditorInfo.IME_ACTION_DONE) {
                        //your functionality 
    
                        // hide virtual keyboard
                        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(etSearch.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN);
    
                        return true;
                    }
                    return false;
                }
            });
    
    0 讨论(0)
提交回复
热议问题