Customize¶
The Yahoo Search SDK allows developers to customize the look and feel of UI components, including the Search Bar, Tab Bar, background, and progress bar.
Customized Search Bar¶
The Yahoo Search SDK provides a default Search Bar implementation. To customize the look and feel of the Search Bar, follow these steps:
Create a View subclass that implements ISearchViewHolder:
public class CustomSearchBar extends LinearLayout implements ISearchViewHolder {...}
Create a layout file that contains this class as your root view:
<?xml version="1.0" encoding="utf-8"?> <com.yahoo.search.yhssdk.showcase.custom.CustomSearchBar xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/custom_search_bar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"> <!--YOUR CONTENT HERE--> </com.yahoo.search.yhssdk.showcase.custom.CustomSearchBar>
Pass your layout file as a parameter to the
SearchActivity
using the builder.SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder(); builder.setCustomHeader(R.layout.custom_search_bar); Intent intent = builder.buildIntent(YourActivity.this); startActivity(intent);
You can view more details about the ISearchViewHolder
Interface and a working
CustomSearchBar
demo in the DemoApp.
Customized Tab bar¶
The tab bar is TabLayout widget from android design support library. All the styling attributes of TabLayout is supported.
All you have to do is override the Search SDK style name Yhssdk_TabLayout
as below. Refer styles xml file in the demo app.
<style name="Yhssdk_TabLayout" parent="Base.Widget.Design.TabLayout">
<item name="tabIndicatorColor">@color/button_material_light</item>
</style>
Customized Search Assist Layout¶
The Yahoo Search SDK provides default search suggestions/assist view. To customize suggestions view follow these steps.
Create a Data binding layout file that contains variables for
SearchAssistData
and click handler callback methodsonClickAssistItem
&onAppendSuggestionItem
inSearchActivity
:<layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="assist" type="com.yahoo.search.yhssdk.data.SearchAssistData"/> <variable name="handler" type="com.yahoo.search.yhssdk.ui.view.SearchActivity"/> </data> <!--YOUR VIEW CONTENT HERE--> </layout>
Pass your layout file as a parameter to the
SearchActivity
using the builder.SearchActivity.IntentBuilder builder = new SearchActivity.IntentBuilder(); builder.setCustomSearchAssist(R.layout.custom_search_assist_item); Intent intent = builder.buildIntent(YourActivity.this); startActivity(intent);
SearchAssistData object fields:
type - Integer constant that specifies the suggestion type. Below are the different types of suggestions.
SEARCH_HISTORY - The suggestion is a history item from the user previous query searches. SEARCH_APPS - App suggestion from the phone that matches the user query. SEARCH_CONTACTS - Contact suggestion from the phone that matches the user query. SEARCH_SUGGEST - Typical query suggestion LOCAL_WEB - similar to SEARCH_HISTORY. SEARCH_TRENDING - Trending suggestion. SHOW_ALL_HISTORY - Show all history. CLEAR_HISTORY - Clear all history. SECTION_DIVIDER - The section divider between different types of suggestions like Apps,Contacts,history etc. label - The actual search suggestion text. icon - The icon to be used for SEARCH_APPS and SEARCH_CONTACTS suggestion.
Assist item click handling
onAppendSuggestionItem
callback for the query builder click event. SDK uses this callback to build the query.onClickAssistItem
callback for the click of search assist item.
You can view more details about the SearchAssistData
object and a
working CustomSearchAssist
demo in the DemoApp.