How to remove white underline in a SearchView widget in Toolbar Android
Once try as follows
View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
v.setBackgroundColor(Color.parseColor("here give actionbar color code"));
Hope this will helps you.
How to remove bottom line in android SearchView component?
When you get a reference to your SearchView
; This will work:
val backgroundView = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate) as View
backgroundView.background = null
How to remove underline on searchview with drawable background
You need to change search_edit_frame, search_plate and search_bar where you have declared this view.
int searchFrameId = searchView.getContext().getResources().getIdentifier("android:id/search_edit_frame", null, null);
View searchFrame = searchView.findViewById(searchFrameId);
searchFrame.setBackgroundResource(R.drawable.rounded_corner);
int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
View searchPlate = findViewById(searchPlateId);
searchPlate.setBackgroundResource(R.drawable.rounded_corner);
int searchBarId = searchView.getContext().getResources().getIdentifier("android:id/search_bar", null, null);
View searchBar = findViewById(searchBarId);
searchBar.setBackgroundResource(R.drawable.rounded_corner);
SearchView in fragment (non in toolbar) can't remove underline
AppCompat supplies two styles for the SearchView:
- the default with underline
- one for use in the Action Bar without underline
You can change the style like this:
<android.support.v7.widget.SearchView
style="@style/Widget.AppCompat.SearchView.ActionBar"/>
The style looks like this:
<style name="Widget.AppCompat.SearchView.ActionBar" parent="Base.Widget.AppCompat.SearchView.ActionBar"/>
<style name="Base.Widget.AppCompat.SearchView.ActionBar">
<item name="queryBackground">@null</item>
<item name="submitBackground">@null</item>
<item name="searchHintIcon">@null</item>
<item name="defaultQueryHint">@string/abc_search_hint</item>
</style>
You could use the attributes directly, of course.
How to change the toolbar SearchView Underline color to GRAY
Finally i got the solution..
View searchplate = (View)searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
searchplate.getBackground().setColorFilter(Color.DKGRAY, PorterDuff.Mode.MULTIPLY);
How can I change the Search Widget Icon to be white for androidx
I am have finally figured it out, so I will answer my own question.
I have changed my menu to this:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:title="Search"
android:icon="@drawable/ic_action_search_white"
app:showAsAction="ifRoom|collapseActionView"
app:actionViewClass="androidx.appcompat.widget.SearchView"/>
The collapseActionView fixes the issue and allows the icon to be picked up. I resisted using it as I was getting weird behaviour.
Once I updated the OnCreateOptionsMenu everything works as expected and the icons are white
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
menuInflater.inflate(R.menu.menu_search, menu)
sv = menu.findItem(R.id.action_search).actionView as SearchView
sv.isSubmitButtonEnabled = false
sv.setOnQueryTextListener(this)
return true
}
For completeness here is the rest of the code:
override fun onQueryTextSubmit(query: String?): Boolean {
getData(query.toString())
return true
}
override fun onQueryTextChange(newText: String?): Boolean {
getData(newText.toString())
return true
}
private fun getData(newText: String) {
searchTerm = "%".plus(newText).plus("%")
//todo ... get the data from the db
}
How to change color of searchView's search icon color programatically inside edittext?
It should work
val searchIcon = searchView.findViewById(R.id.search_mag_icon) as ImageView
searchIcon.setColorFilter(Color.Red)
Related Topics
Error:Execution Failed for Task ':App:Kaptdebugkotlin'
Not Seeing Nexus7 in Eclipse's Android Devices
How to Embed Vlc Media Player to My Android App
How to Setup Multiple Alarms in Android
Crop Square Image to Circle - Programmatically
Custom Listview Fast Scrollbar in Android
How to Capture Key Events from Bluetooth Headset with Android
Isvalidfragment Android API 19
Flutter Insecure Http Is Not Allowed by Platform
Add Drop Shadow Effects to Edittext Field
Set a Consistent Style to All Edittext (For E.G.)
Httpurlconnection.Openconnection Fails Second Time
Android Convert Px to Dp (Video Aspect Ratio)
Retain The Fragment Object While Rotating