I want to customize the default Android SearchView to make it look like this:
I could use reflection for accessing to propeties of SearchView and use ImageSpan to add the magnifier icon before "Search" (the hint text) then set it as hint text for SearchView's EditText.
But I also need the magnifier to be align in the SearchView with exact pixel values as illustrated in the image above. I haven't figure out any way to achieve this yet.
How can I implement it?
Related
I want to hide the vertical bar on searchview edittext if the hint appears and the user didn't write any query and if he tried to make a query it will be show after the word written and if he removes the query and the hint get back the vertical bar hide again.
The vertical bar I mean appears in this image with gray color in the start of the searchview edittext also I want it appears like this image on query written
I have tried this in the custom style for searchview but it didn't hide the cursor
<item name="android:textCursorDrawable">#null</item>
As far as I know, you can hide the cursor by following
android:queryBackground="#android:color/transparent"
Although this might also remove the bottom horizontal bar, I guess you can make a work around about it to set a query listener and check if the text of SearchView is empty then set background as transparent else default.
I have SearchView in my toolbar
and I am wondering how can I change search icon inside SearchView Edittext drawableleft icon color programatically?
searchView = menu.findItem(R.id.action_search)?.actionView as? SearchView
I know using findViewById of SearchView I can find components of SearchView and do it
But it doesn't work and I would like to know if it possible to change edittext underline color programatically?
Here is my image you can see what I mean and I have changed the close button color I want to have the same for other components
link
val searchText = searchView?.findViewById(R.id.search_src_text) as SearchView.SearchAutoComplete
searchText.compoundDrawables[0].setTint(Color.RED)
It should work
val searchIcon = searchView.findViewById(R.id.search_mag_icon) as ImageView
searchIcon.setColorFilter(Color.Red)
I make some researches and find info that HintIcon is private field and you can't change in programmatically. I'm not sure about that but only one way that I found yet was about changing XML attribute.
app:searchHintIcon="#drawable/ic_search"
After that, the whole icon was changed so you could just create a simple search vector with a colour that is needed.
Probably there are other ways to change it but right now I'm not really sure.
I'm trying to implement an Material Design like Toolbar including a search (using the support SearchView).
I run into the problem that I can't get the SearchView start at the same position (72dp from the left border) as the title. It's some dp more right than the title. How can I fix this?
I put contentInsetStart="72dp" to the toolbar for getting the title at the mentioned line, but the SearchView now starts like 100dp from the left.
I want to have it like this:
The right solution for my problem was setting app:titleMarginStart="16dp" for the android.support.v7.widget.Toolbar.
Try to override abc_dropdownitem_text_padding_left to 0dp or negative value using ref.xml. Default value is 8dp, when you add 72dp content inset this will move all content to right including their padding which contribute to those you see as 100dp.
I want to change the searchview color on selection/focus.
I am using ActionBarSherlock with default theme. I tried changing theme but didn't have any luck there.
Here's an image in which searchview focus color is yellow:
How can I change it to transparent?
Simplest way here is to write a selector for it and place your search image in it.
I am using action bar support v7 library. When I expand search view I get look like this.
I dont want this search icon on left. Instead I want to place it in hint like image below.
I want to do this programmatically. How can I achieve this?
Thanks.
I think I figured out what the answer is.
To expand searchview by default if I use
mSearchView.setIconifiedByDefault(false);
it will show search bar like first image
If I use mSearchView.onActionViewExpanded(); then it shows like second image.