I'm using https://github.com/mancj/MaterialSearchBar to set a search bar with a menu burger. I can't change of API.
Here is what I obtained:
How to...:
Reduce the padding-left of the text?
Change the font-family of the latter?
Finally, disable boldness?
NB: these questions are completed by some others in the next section, According to the documentation.
mt_aBCD
are the XML attributes that allow us to customize the search bar. However, the above ones don't exist. Their Java equivalent (setABCD
neither).
By the way, note that there isn't a lot of Github activity for this API. I can't replace the latter with another one. What solution would you give me?
I edited my build file, then I simply added the search bar in my XML layout:
<com.mancj.materialsearchbar.MaterialSearchBar
android:id="@+id/material_search_bar"
style="@style/MaterialSearchBarLight"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
app:layout_constraintBottom_toBottomOf="@+id/toolbar"
app:layout_constraintEnd_toEndOf="@+id/toolbar"
app:layout_constraintStart_toStartOf="@+id/toolbar"
app:layout_constraintTop_toTopOf="@+id/toolbar"
app:mt_maxSuggestionsCount="10"
app:mt_navIconEnabled="true"
app:mt_placeholder="@string/search_placeholder" />
this library not support font-familly. This question exists in the github block "ISSUE"
padding for you text not support like and "disable boldness"
searchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
try {
final Field placeHolder = searchBar.getClass().getDeclaredField("placeHolder");
placeHolder.setAccessible(true);
final TextView textView = (TextView) placeHolder.get(searchBar);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
// fix trouble number 1 paddingLeft
textView.setPadding(0, 0, 0, 0);
final RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) textView.getLayoutParams();
layoutParams.setMargins(0,0,0,0);
//fix trouble number 2 font-family and number 3 Finally, disable boldness?
Typeface typeface = Typeface.createFromAsset(getAssets(), getString(R.string.roboto_medium));
//<string name="roboto_medium">fonts/Roboto-Medium.ttf</string>
textView.setTypeface(typeface);
textView.setText("Hello World!");
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Burger menu have size 48dp it is not margins(DeclaredField = navIcon)
copy this library in you project and edited all you want .
you can do it because this library used license MIT
most importantly specify the original author