I've got this problem but the thing is that I do have a title
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/tools">
<!-- Search, should appear as action button -->
<item
android:title="#string/action_search"
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:showAsAction="ifRoom" />
<item
android:title="#string/action_settings"
android:id="#+id/action_settings"
android:showAsAction="never" />
</menu>
in the strings xml file i did the strings, the program even switches the action_search and action_settings with its string - search and settings.
Just a wrong XML namespace! Try with:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
</menu>
And as G.T. suggested you should consider using appcompat on the showAsAction property (only needed if you want to support API < 11):
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/item1"
android:icon="#drawable/ic_launcher"
app:showAsAction="ifRoom|withText"
android:title="#string/Add_New" />
</menu>
Note:
The appcompat library is compatible with some old Android versions (API 7+) that can't handle the showAsAction property because they don't have the ActionBar (API < 11).
can you remove those things xmlns:android="schemas.android.com/apk/res-auto"; xmlns:android="schemas.android.com/tools";
Also try to follow Goolge dev examples here http://developer.android.com/guide/topics/ui/menus.html
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/new_game"
android:icon="#drawable/ic_new_game"
android:title="#string/new_game"
android:showAsAction="ifRoom"/>
<item android:id="#+id/help"
android:icon="#drawable/ic_help"
android:title="#string/help" />
</menu>
It actually need a namespace to identify the process.
<?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_shuffle"
android:icon="#drawable/android_music_player_rand"
android:orderInCategory="1"
app:showAsAction="always"
android:title="Shuffle"
android:onClick="shuffle"/>
<item
android:id="#+id/action_end"
android:icon="#drawable/end"
android:orderInCategory="2"
app:showAsAction="always"
android:title="End"
android:onClick="end"/>
</menu>
Related
I'm using AppCompatActivity with theme Theme.MaterialComponents.DayNight.DarkActionBar
In AndroidTV I can't have the focus on the ActionBar menu buttons I added (to the right) using D-Pad :
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".home.HomeActivity">
<group android:checkableBehavior="single">
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_search"
android:orderInCategory="2"
android:title="#string/search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="collapseActionView|ifRoom" />
<item
android:id="#+id/action_refresh"
android:icon="#drawable/ic_refresh"
android:orderInCategory="1"
android:title="#string/refresh"
app:showAsAction="collapseActionView|ifRoom" />
</group>
</menu>
Is there any solution ?
Thanks in advance for help !
I want to hide all icons in action bar when user touches the search icon. But one icon is not hiding.
My xml:
<?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_search"
android:icon="#drawable/ic_search_white_36dp"
android:title="Ara"
app:showAsAction="always"
android:iconifiedByDefault="true"
app:actionViewClass="android.widget.SearchView"/>
<item android:id="#+id/action_shuffle"
android:icon="#drawable/ic_autorenew_white_24dp"
android:title="Karıştır"
app:showAsAction="always" />
<item android:id="#+id/action_premium"
android:icon="#drawable/ic_star_white_24dp"
android:title="Premium"
app:showAsAction="always" />
<item android:id="#+id/action_favorites"
android:icon="#drawable/ic_people_white_24dp"
android:title="Takip Listesi"
app:showAsAction="always" />
<item android:id="#+id/action_settings"
android:icon="#drawable/ic_settings_white_24dp"
android:title="Settings"
app:showAsAction="always" />
<item android:id="#+id/action_fullpicture"
android:icon="#drawable/ic_action_picture"
app:showAsAction="always"
android:visible="false" />
</menu>
Before:
After:
How can I hide action_shuffle too? Other icons automaticly hiding I didn't do anything special.
You should change the app:showAsAction = "always" to app:showAsAction = "ifRoom".
Other way could be this answer, take a look.
Please help me. I use the context menu in Action Bar (CAB). Listing menu has the following 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/add_cxtmenu"
android:icon="#android:drawable/ic_menu_add"
android:showAsAction="always"
android:orderInCategory="1"
android:title="edit"/>
<item/>
<item
android:id="#+id/edit_cxtmenu"
android:icon="#android:drawable/ic_menu_edit"
android:showAsAction="always"
android:orderInCategory="2"
android:title="edit"/>
<item
android:id="#+id/delete_cxtmenu"
android:icon="#android:drawable/ic_menu_delete"
android:showAsAction="always"
android:orderInCategory="3"
android:title="delete"/>
</menu>
So the menu should consist of three items. Each item has a parameter android:showAsAction="always"
In the end, I had to get three icons on the panel ActionBar. But in reality, I have two icons together into a button overflowbutton. How to fix it? I can not find the answer to this problem.
Theme my app
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
Try 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:id="#+id/add_cxtmenu"
android:icon="#android:drawable/ic_menu_add"
app:showAsAction="always"
android:orderInCategory="1"
android:title="edit"/>
<item/>
<item
android:id="#+id/edit_cxtmenu"
android:icon="#android:drawable/ic_menu_edit"
app:showAsAction="always"
android:orderInCategory="2"
android:title="edit"/>
<item
android:id="#+id/delete_cxtmenu"
android:icon="#android:drawable/ic_menu_delete"
app:showAsAction="always"
android:orderInCategory="3"
android:title="delete"/>
</menu>
Try to change this:
android:showAsAction="always"
For this:
app:showAsAction="always"
Also you couldn´t have enought room. Try to remove your title or do it small.
I have this error in menu_main.xml file under menu folder:
error:Error parsing XML unbound prefix.
my code is
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"
appcompat:showAsAction="always"/>
Unbound prefix. You should look at android:, app: and appcompat:.
This line
<menu xmlns:android="http://schemas.android.com/apk/res/android">
defines the namespace android (the "ns" of "xmlns"). app and appcompat need to be defined the same way.
<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">
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"
app:showAsAction="collapseActionView|always"
app:actionViewClass="android.support.v7.widget.SearchView/>
</menu>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never"/>
<item
android:id="#+id/menu_search"
android:title="#string/menu_search"
android:showAsAction="always"/>
</menu>
please check the below solutions.
You see this error with an incorrect namespace, or a typo in the attribute. Like 'xmlns' is wrong, it should be xmlns:android
otherwise put full xml code.
I have this menu on my android app
<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="com.example.app.MainActivity">
<item
android:id="#+id/action_settings"
android:title="root"
app:showAsAction="always">
<menu>
<item
android:title="item 1"
app:showAsAction="always" />
<item
android:title="item 2"
app:showAsAction="always" />
<item
android:title="item 3"
app:showAsAction="always" />
</menu>
</item>
On API 14+ it works as expected: click on button gives me dropdown menu.
But on API 8 it works strange
Where is my problem? What should I do?