# SimpleSearchView **Repository Path**: chinasoft_ohos/SimpleSearchView ## Basic Information - **Project Name**: SimpleSearchView - **Description**: 提供一个简单的搜索控件 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2021-04-14 - **Last Updated**: 2022-04-15 ## Categories & Tags **Categories**: harmonyos-advanced **Tags**: None ## README # SimpleSearchView #### 项目介绍 - 项目名称:SimpleSearchView - 所属系列:openharmony 第三方组件适配移植 - 功能:一款简单的基于鸿蒙风格的搜索控件 - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio2.2 beta1 - 基线版本:Release 0.1.6 #### 效果演示 Card sample        Bar sample #### 安装教程 在moudle级别下的build.gradle文件中添加依赖 ```groovy // 添加maven仓库 repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/releases/' } } // 添加依赖库 dependencies { implementation 'com.gitee.chinasoft_ohos:simplesearchview:1.0.1' } ``` 在sdk6,DevEco Studio2.2 beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 添加SimpleSearchView到你的DirectionalLayout 设置监听器 simpleSearhView.setOnQueryTextListener(new SimpleSearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { Log.d("SimpleSearchView", "Submit:" + query); return false; } @Override public boolean onQueryTextChange(String newText) { Log.d("SimpleSearchView", "Text changed:" + newText); return false; } @Override public boolean onQueryTextCleared() { Log.d("SimpleSearchView", "Text cleared"); return false; } }); 设置TabLayout ``` simpleSearchView.setTabLayout(findViewById(R.id.tabLayout)); ``` 手动开启和关闭搜索框 ``` simpleSearchView.showSearch(); simpleSearchView.closeSearch(); ``` OnBackPressed ``` 自动关闭搜索框 @Override public void onBackPressed() { if (searchView.onBackPressed()) { return; } super.onBackPressed(); } ``` Style ``` Bar style (default): app:type="bar" Card style: app:type="card" ``` 打开和关闭监听 ``` simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() { @Override public void onSearchViewShown() { Log.d("SimpleSearchView", "onSearchViewShown"); } @Override public void onSearchViewClosed() { Log.d("SimpleSearchView", "onSearchViewClosed"); } @Override public void onSearchViewShownAnimation() { Log.d("SimpleSearchView", "onSearchViewShownAnimation"); } @Override public void onSearchViewClosedAnimation() { Log.d("SimpleSearchView", "onSearchViewClosedAnimation"); } }); ``` 属性: ``` if (attrs.getAttr("type").isPresent()) { setCardStyle(AttrValue.get(attrs, "type", style)); } if (attrs.getAttr("backIconAlpha").isPresent()) { setBackIconAlpha(AttrValue.get(attrs, "backIconAlpha", BACK_ICON_ALPHA_DEFAULT)); } if (attrs.getAttr("iconsAlpha").isPresent()) { setIconsAlpha(AttrValue.get(attrs, "iconsAlpha", ICONS_ALPHA_DEFAULT)); } if (attrs.getAttr("backIconTint").isPresent()) { setBackIconColor(AttrValue.get(attrs, "backIconTint", ResourceTable.Color_colorAccent)); } if (attrs.getAttr("iconsTint").isPresent()) { setIconsColor(AttrValue.get(attrs, "iconsTint", ResourceTable.Color_colorAccent)); } if (attrs.getAttr("cursorColor").isPresent()) { setCursorColor(AttrValue.get(attrs, "cursorColor", "#FF4081")); } if (attrs.getAttr("hintColor").isPresent()) { setHintTextColor(AttrValue.get(attrs, "hintColor", "#8A000000")); } if (attrs.getAttr("searchBackground").isPresent()) { ShapeElement shapeElement = new ShapeElement(); String color = AttrValue.get(attrs, "searchBackground","#FFFFFF"); shapeElement.setRgbColor(RgbColor.fromArgbInt(Color.getIntColor(color))); setSearchBackground(shapeElement); } if (attrs.getAttr("searchBackIcon").isPresent()) { setBackIconDrawable(AttrValue.get(attrs, "searchBackIcon", new VectorElement(getContext(), ResourceTable.Graphic_ic_arrow_back_black_24dp))); } if (attrs.getAttr("searchClearIcon").isPresent()) { setClearIconDrawable(AttrValue.get(attrs, "searchClearIcon", new VectorElement(getContext(), ResourceTable.Graphic_ic_close_black_24dp))); } if (attrs.getAttr("searchVoiceIcon").isPresent()) { setVoiceIconDrawable(AttrValue.get(attrs, "searchVoiceIcon", new VectorElement(getContext(), ResourceTable.Graphic_ic_voice_search_black_24dp))); } if (attrs.getAttr("voiceSearch").isPresent()) { enableVoiceSearch(AttrValue.get(attrs, "voiceSearch", isAllowVoiceSearch)); } if (attrs.getAttr("voiceSearchPrompt").isPresent()) { setVoiceSearchPrompt(AttrValue.get(attrs, "voiceSearchPrompt", "")); } if (attrs.getAttr("hint").isPresent()) { setHint(AttrValue.get(attrs, "hint", "Search")); } if (attrs.getAttr("inputType").isPresent()) { setInputType(AttrValue.get(attrs, "inputType", TWO)); } if (attrs.getAttr("textColor").isPresent()) { setTextColor(AttrValue.get(attrs, "textColor", ResourceTable.Color_default_textColor)); } ``` #### 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与安卓原组件基本无差异 #### 版本迭代 - 1.0.0 #### 版权和许可信息 ``` Copyright (C) 2018 Fernando Augusto Heeren Falkiewicz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```