【问题标题】:Customise android search view自定义 android 搜索视图
【发布时间】:2019-04-17 02:43:04
【问题描述】:

我的搜索视图如下所示

我希望它类似于以下内容

下面是代码

<SearchView
    android:id="@+id/search_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:iconifiedByDefault="false"
    android:keyboardNavigationCluster="true"
    android:queryHint="@string/search_teams"
    android:textColor="@color/grey" />

我希望能够通过更改字体左对齐和自定义搜索视图中的查询提示。默认情况下,文本居中对齐,有什么办法可以改变吗?

【问题讨论】:

  • 你也想要右边的扬声器吗?
  • 是的,搜索视图也加了下划线
  • 您可以使用带有drawableStartdrawableEnd 的简单editText
  • SerachView 是一个小部件/容器,它在内部使用许多其他视图,如 textview 和内部的其他几个视图来形成SerachView 布局。我要做的是,阅读 SerachView 类并找到正在使用的TextView,然后通过searchView.findViewById(serachviewTextViewId) 获取对该TextView 的引用,然后将该属性应用于TextView

标签: android android-layout searchview text-alignment android-search


【解决方案1】:

您需要在单独的 xml 文件中指定 Searchable Configuration 并设置以下属性

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_label"
    android:hint="@string/search_hint"
    android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
</searchable>

从文档中参考here 了解更多选项

您可以在搜索对话框或小部件中添加语音搜索功能 通过将 android:voiceSearchMode 属性添加到您的可搜索项 配置。这添加了一个语音搜索按钮,用于启动语音 提示。

【讨论】:

    猜你喜欢
    • 2012-12-17
    • 1970-01-01
    • 2016-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多