适用于 Android 的材料设计搜索栏
将 SearchBar 添加到您的项目中: 将此代码添加到项目级 build.gradle 文件中
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}将依赖关系添加到应用级 build.gradle 文件中
dependencies {
implementation 'com.github.mancj:MaterialSearchBar:X.X.X'
}
然后将 SearchBar 添加到您的 Activity 中:
<com.mancj.materialsearchbar.MaterialSearchBar
style="@style/MaterialSearchBarLight"
app:mt_speechMode="true"
app:mt_hint="Custom hint"
app:mt_maxSuggestionsCount="10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/searchBar" />MaterialSearchBar 具有以下 xml 属性:
| 属性 | 描述 |
|---|---|
| mt_speechMode | 如果设置为 true,则会显示麦克风图标,而不是搜索图标 |
| mt_maxSuggestionsCount | 指定存储的最大搜索查询数量 |
| mt_navIconEnabled | 设置导航图标是否可用 |
| mt_roundedSearchBarEnabled | 在 v21+ 版本上使用圆角形状的搜索栏,并在低版本上恢复默认值 |
| mt_dividerColor | 设置建议和菜单分隔线的颜色 |
| mt_searchBarColor | 设置搜索栏的主色调 |
| mt_menuIconDrawable | 设置菜单图标的可绘制对象 |
| mt_searchIconDrawable | 当语音模式为 false 时,设置搜索图标的可绘制对象 |
| mt_speechIconDrawable | 设置可绘制对象 t |
暂无开放 Issues,或尚未同步最近议题。