I have this xml code
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_settings"
android:title="Settings"/>
<item android:id="#+id/action_search"
android:title="Search"
android:icon="#android:drawable/ic_menu_search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
but there is a problem in (v7.widget.SearchView)it is not working, and in inspection
results it show(v7.widget.SearchView) no longer valid.
can someone help me in this problem?(and sorry for my bad English)
as you said v7.widget.SearchView is no longer valid, so you have to use the updated version of it androidx.appcompat.widget.SearchView
Related
I am trying to add a shopping cart icon with the code below the output I get is two options namely create order and order in settings, and Icon is nowhere to be seen.
Can anyone tell me what's wrong in my code?
My code:
<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
app:showAsAction="never"
android:title="order" />
<item
android:title="#string/create_order"
android:id="#+id/action_create_order"
android:orderInCategory="1"
android:icon="#drawable/ic_add_shopping_cart_black_48dp"
app:showAsAction="always"
/>
</menu>
Your xmlns android schema is wrong. you have written this :
xmlns:android= "https://schemas.android.com/apk/res/android"
instead of this write this :
xmlns:android="http://schemas.android.com/apk/res/android"
Try this code :
<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
app:showAsAction="never"
android:title="order" />
<item
android:title="#string/create_order"
android:id="#+id/action_create_order"
android:orderInCategory="1"
android:icon="#drawable/ic_album"
app:showAsAction="always"
/>
</menu>
Since you set the showAsAction attribute to never, then these menu items will never show as action views. Try this:
<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android= "https://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="ifRoom|withText"
/>
<item
android:title="#string/create_order"
android:id="#+id/action_create_order"
android:orderInCategory="100"
android:icon="#drawable/ic_add_shopping_cart_black_24dp"
android:showAsAction="ifRoom|withText"
app:showAsAction="ifRoom"
/>
</menu>
I'm trying use Navigation Drawer. Everything is okay, but there is an error here:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
>
<item
android:id="#+id/action_example"
android:orderInCategory="100"
android:title="#string/action_example"
android:showAsAction="ifRoom"
/>
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
android:showAsAction="ifRoom"
/>
</menu>
Red underlined (two)line is:
android:showAsAction="ifRoom"
Information message is here
And This line is grayed.
xmlns:app="http://schemas.android.com/apk/res-auto"
Any help can be help!
change this line
android:showAsAction="ifRoom"
to
app:showAsAction="ifRoom"
And Clean Build your Project.You are done.Hope it will help.Thanks
I write code like this, but it doesnt work.
I just inflate menu in java, nothing else.
I'm using toolbar(v7) instead of actionBar.
Any problem in here??
(No Clicked effect- too.)
<item android:id="#+id/action_search"
android:title="Search"
android:icon="#drawable/abc_ic_search_api_mtrl_alpha"
app:showAsAction="always|collapseActionView"
app:theme="#style/MySearchViewStyle"
app:actionViewClass="android.support.v7.widget.SearchView" />
Try this. Because, This one Works for me ...
<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:icon="#android:drawable/ic_menu_search"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="Search"/>
</menu>
In the following snippet, what does yourapp refer to? I try using the package name, then the project name, but they aren't the answer as the code does not compile
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_search"
android:title="#string/action_search"
android:icon="#drawable/ic_action_search"
yourapp:showAsAction="ifRoom|collapseActionView"
yourapp:actionViewClass="android.support.v7.widget.SearchView" />
</menu>
if you are going to use SearchView in API less than 11 (obviously you are not) you must extend your activity from ActionBarCompatand in your xml layout of your menu you must use another xml name space for showAsAction and actionViewClass. then you must use searchview from support library.(android.support.v7.widget.SearchView) the xml name space is arbitary and here you called it yourapp. So you must use below code because of android:minSdkVersion="11":
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item android:id="#+id/action_search"
android:title="#string/action_search"
android:icon="#drawable/ic_action_search"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
</menu>
can someone explain why the 2nd item is not being added to the overflow menu in the actionbar? The settings displays correctly, and profile displays if I set the showAsAction to always, but I would rather have profile appear in the overflow menu.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:Molo="http://schemas.android.com/apk/res-auto" >
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/settings"
Molo:showAsAction="always" />
<item android:id="#+id/action_profile"
android:title="#string/action_profile"
android:icon="#drawable/user"
Molo:showAsAction="never"/>
</menu>
Add android:showAsAction mapped to the same value as Molo:showAsAction, as that should help on newer devices.
just removed the Molo:showAsAction="never" ,Try this..
<?xml version="1.0" encoding="utf-8"?>
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/settings"
Molo:showAsAction="always" />
<item android:id="#+id/action_profile"
android:title="#string/action_profile"
android:icon="#drawable/user" />