Apr 8 | 7:20 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Apr 8 | 7:25 PM |
Eric | has entered the room |
Mark M. |
hello, Eric!
|
Mark M. |
how can I help you today?
|
Eric |
afternoon mark
|
Eric |
I am encountering issues implementing a searchview in a toolbar
|
Eric |
I cannot see it in my toolbar
|
Mark M. |
how are you adding it to the Toolbar?
|
Apr 8 | 7:30 PM |
Eric | |
Eric |
View paste
|
Mark M. |
are you getting the icon? or nothing at all?
|
Eric |
I don't see any icon in my toolbar. I just see a title and back nav
|
Mark M. |
actually, that android:icon value looks wrong -- are you sure there is a framework icon named ic_menu_search?
|
Mark M. |
if that is an icon that you added to your app, it would be @drawable/ic_menu_search
|
Eric |
yes, it compiles and I see a preview in my xml for my menu class
|
Mark M. |
OK, then I recommend two experiments:
|
Mark M. |
1. Humor me, and try changing it to @drawable/ic_menu_search, or to some other icon that is in your app, and see if you get better results
|
Mark M. |
2. Try removing app:actionViewClass="androidx.appcompat.widget.SearchView" and see if you now get the icon (but, obviously, no SearchView)
|
Mark M. |
for #2, if you get the icon, that means that the Toolbar is not liking that attribute in the menu resource -- if you do not get the icon, then the Toolbar is not liking the menu resource at all
|
Apr 8 | 7:35 PM |
Mark M. |
(or, if you do not get the icon, perhaps you are no\t actually adding the menu resource to the Toolbar)
|
Eric |
I tried both and got the same result. An icon still doesnt show to expand a searchview.
|
Eric |
Could it be my activity theme? "@style/Theme.AppCompat.NoActionBar"
|
Mark M. |
that seems OK
|
Mark M. |
how are you teaching the Toolbar about this menu resource?
|
Apr 8 | 7:40 PM |
Eric |
View paste
|
Mark M. |
I don't think setSupportActionBar() and inflateMenu() work together
|
Mark M. |
if you want inflateMenu(), you should not need setSupportActionBar()
|
Mark M. |
conversely, if you want setSupportActionBar(), I think that you would use the normal function overrides of onCreateOptionsMenu() and onOptionsItemSelected(), instead of inflateMenu()
|
Eric |
ok I got rid of setSupportActionBar.
|
Eric |
it works now, awesome mark
|
Mark M. |
glad it worked!
|
Apr 8 | 7:45 PM |
Eric |
it got rid of my upnav, is there a way to add it in via my binding obj?
|
Mark M. |
are you using Jetpack Navigation?
|
Eric |
no
|
Eric |
just a regular activity for now
|
Mark M. |
hmmmm... I'm a bit surprised that you had up navigation then to begin with, as I didn't think that setSupportActionBar() did that... but it's been a while since I actively worked with this, so I forget the details
|
Mark M. |
but, you could use setNavigationIcon() on the Toolbar to add it back in
|
Mark M. |
and use setNavigationOnClickListener() to find out when the user taps it
|
Apr 8 | 7:50 PM |
Eric |
worked like a charm!
|
Eric |
well that's all for today. I appreciate it as usual
|
Mark M. |
you're welcome!
|
Eric |
bye
|
Eric | has left the room |
Apr 8 | 8:25 PM |
Mark M. | turned off guest access |