简体   繁体   English

为Android TV应用程序的BrowseFragment更改SearchView默认图标?

[英]Change SearchView default icon for BrowseFragment for Android TV applications?

For Leanback BrowseFragment , by default there is a search view to the left of the screen. 对于Leanback BrowseFragment ,默认情况下在屏幕左侧有一个搜索视图。 Is it a way to change the default icon of that SearchOrbView or hide it. 是否可以更改或隐藏该SearchOrbView的默认图标。

https://cdn-images-1.medium.com/max/800/1*oIFbcdjYrIqxU55-B23tjA.gif https://cdn-images-1.medium.com/max/800/1*oIFbcdjYrIqxU55-B23tjA.gif

As stated by the documentation on developer.android.com if you don't call setOnSearchClickedListener the Search orb will be invisible: developer.android.com上的文档所述,如果您不调用setOnSearchClickedListener则搜索球将不可见:

public void setOnSearchClickedListener (View.OnClickListener listener) 公共无效setOnSearchClickedListener (View.OnClickListener侦听器)

Sets a click listener for the search affordance. 设置点击侦听器以提供搜索能力。

The presence of a listener will change the visibility of the search affordance in the fragment title. 侦听器的存在将更改片段标题中搜索功能的可见性。 When set to non-null, the title will contain an element that a user may click to begin a search. 设置为非null时,标题将包含用户可以单击以开始搜索的元素。

If you want instead change the icon of the SearchOrbView you can do it editing your style: 如果您想改为更改SearchOrbView的图标,则可以编辑样式:

<style name="Theme.Example.Leanback" parent="Theme.Leanback">
    <item name="searchOrbViewStyle">@style/CustomSearchOrbView</item>
</style>

<style name="CustomSearchOrbView" parent="Widget.Leanback.SearchOrbViewStyle">
    <item name="searchOrbIcon">@drawable/your_search_orb_icon</item>
</style>

if you want to change the icon then in you styles.xml 如果要更改图标,则在您的styles.xml中

 <style name="NewSeachTheme" parent="Theme.Leanback">
    <item name="searchOrbViewStyle">@style/CustomSearchOrbView</item>
    <item name="defaultSearchColor">@color/transparent</item>
</style>

<style name="CustomSearchOrbView" parent="Widget.Leanback.SearchOrbViewStyle">
    <item name="searchOrbIcon">add your drawable here</item>
    <item name="searchOrbIconColor">@color/transparent</item>
</style>

Here the searchOrbIconColor is transparent because if your icon is small then the default icon color will be shown behind the search icon you use. 这里的searchOrbIconColor是透明的,因为如果您的图标很小,则默认图标颜色将显示在您使用的搜索图标后面。 Then add the new style "NewSeachTheme" to the Theme in manifest. 然后将新样式“ NewSeachTheme”添加到清单中的主题。 Happy coding :) 快乐的编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM