Main.xml Error About Library - android

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

Related

v7.widget.SearchView is no longer valid

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

Menu items shloud specify a title error and icon not showing

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>

Android menu item with both icon and text together when showAsAction is never

Hi, how can I make my menu items have icons as well when showAsAction is never ?
Use android:actionLayout in menu item tag to specify custom lyout (icon with text).
Menu item will look like:
<item
android:id="#+id/edit_menu"
android:actionLayout="#layout/custom_edit_row"
android:orderInCategory="100"
android:title="#string/edit"
app:showAsAction="always"></item>
Edit
custom_edit_row.xml
will be:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
style="#android:style/Widget.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true">
<ImageView
android:id="#+id/imageViewEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/edit_ic" />
<TextView
android:id="#+id/tvEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Edit" />
<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=".YourActivityName">
<item
android:id="#+id/action_settings"
android:icon="#android:drawable/btn_dialog"
android:title="#string/action_settings"
app:showAsAction="always">
<menu>
<item
android:id="#+id/profile"
android:icon="#drawable/common_google_signin_btn_icon_light_disabled"
android:title="PROFILE"
app:showAsAction="always" />
</menu>
</item>
Use this menu file, it worked fine for me.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_m"
android:showAsAction="never"
android:title="menu">
<menu>
<item
android:id="#+id/action_one"
android:icon="#android:drawable/ic_popup_sync"
android:showAsAction="always"
android:title="Sync"/>
<item
android:id="#+id/action_two"
android:icon="#android:drawable/ic_dialog_info"
android:title="About"/>
</menu>
</item>
</menu>
In createOptionsMenu, set the icon and text to MenuItem.
Elaborate the problem a little more.
Just change root item of Harry Mad answer
<item
android:title="Ещё"
app:showAsAction="always"
android:icon="#drawable/ic_more_vert">
...

android toolbar why do i get options menu instead of icons

so i made my own toolbar with a menu and i am infalting it:
toolbarBottom.inflateMenu (R.menu.user_interaction);
and this is the menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res/android">
<item app:title="Edit"
app:id="#+id/post"
app:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item app:id="#+id/menu_share"
app:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
app:title="Undo" />
<item app:id="#+id/test"
app:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
app:title="Redo" />
</menu>
what i get now is the 3 android option dots on the right side of my bar. If i press it my 3 menu´s appear. What i want is the 3 menu items to appear on the bar itself witht he 3 icon drawables.
Where is my mistake? Did i forgot something? :O
ok i solved it like this:
<?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:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>
It should be:
<?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:title="Edit"
android:id="#+id/post"
android:icon="#drawable/ic_action_pinboard_white"
app:showAsAction="always"
/>
<item android:id="#+id/menu_share"
android:icon="#drawable/ic_action_recent_white"
app:showAsAction="always"
android:title="Undo" />
<item android:id="#+id/test"
android:icon="#drawable/ic_action_groups_white"
app:showAsAction="always"
android:title="Redo" />
</menu>

Adding options in overflow 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" />

Categories

Resources