-
-
Notifications
You must be signed in to change notification settings - Fork 0
Basic implementation
Federico Navarrete edited this page Jul 5, 2019
·
13 revisions
<tk.supernovaic.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" />
Edit the Activity (AppCompatActivity) where you are working and add the following parts:
-
MaterialSearchBar.IOnSearchActionListener
interface for reading the buttons actions in the Bar. - Create an object of the type
MaterialSearchBar
. - Create a listener for listening your Bar.
Example code:
public partial class YourClassActivity : AppCompatActivity, MaterialSearchBar.IOnSearchActionListener
{
private MaterialSearchBar MSearchBar { get; set; }
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
MSearchBar = FindViewById<MaterialSearchBar>(Resource.Id.searchBar);
MSearchBar.SetOnSearchActionListener(this);
MSearchBar.AddTextChangeListener(new MaterialSearchBarListener());
}
void MaterialSearchBar.IOnSearchActionListener.OnButtonClicked(int p0)
{
switch (p0)
{
case MaterialSearchBar.ButtonNavigation:
Drawer.OpenDrawer((int)GravityFlags.Left);
break;
case MaterialSearchBar.ButtonSpeech:
break;
case MaterialSearchBar.ButtonBack:
MSearchBar.DisableSearch();
break;
}
}
}
public partial class YourClassActivity
{
private class MaterialSearchBarListener : Java.Lang.Object, ITextWatcher
{
public void AfterTextChanged(IEditable s)
{
}
public void BeforeTextChanged(ICharSequence s, int start, int count, int after)
{
}
public void OnTextChanged(ICharSequence s, int start, int before, int count)
{
}
}
}
YouTube | Amazon | Goodreads | Cyber Prophets | Sharing Your Stories | TikTok | ||
---|---|---|---|---|---|---|---|
© Federico Navarrete and Supernova IC, 2017-2024. Based on: MaterialSearchBar by Mansur Nashaev.