首页 > 代码库 > Android自定义搜索框

Android自定义搜索框

搜索框里的虚拟键盘

xml如下

<EditText android:id="@+id/et_shopshow_search"            android:layout_width="144dp"            android:layout_height="40dp"            android:singleLine="true"            android:paddingLeft="8dp"            android:paddingRight="8dp"            android:drawablePadding="8dp"            android:hint="@string/kuanhao"            android:background="@color/white"            android:drawableLeft="@drawable/searchcommon_icon"            android:focusableInTouchMode="true"            android:textSize="16sp"            android:layout_marginLeft="8dp"            android:layout_marginRight="8dp"            android:layout_weight="1"            android:imeOptions="actionSearch" />

在代码里加入keydown时间的重写

final EditText et_search=(EditText)findViewById(R.id.et_shopshow_search);        et_search.setOnEditorActionListener(new OnEditorActionListener() {            @Override            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                if(actionId ==EditorInfo.IME_ACTION_SEARCH){//这是搜索                    // 先隐藏键盘                    ((InputMethodManager) et_search.getContext().getSystemService(Context.INPUT_METHOD_SERVICE))                    .hideSoftInputFromWindow(ShopShowActivity.this.getCurrentFocus().getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);                                         //根据搜索框内容进行查询                     _styleCode=v.getText().toString().trim();                    InitPageTask task = new InitPageTask(ShopShowActivity.this);                    task.execute("");                    return true;                }                return false;            }        });

 

Android自定义搜索框