-1

What i am trying to do ::

enter image description here

What is happening ::

enter image description here


My code::

actionbar_sort_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/searchID"
        android:icon="@drawable/ic_action_search"
        android:showAsAction="ifRoom|withText"
        android:title="Search"/>
    <item
        android:id="@+id/featuredID"
        android:icon="@drawable/ic_action_featured"
        android:showAsAction="ifRoom|withText"
        android:title="Featured"/>
    <item
        android:id="@+id/dealsID"
        android:icon="@drawable/ic_action_deal"
        android:showAsAction="ifRoom|withText"
        android:title="Deals"
        />
    <item
        android:id="@+id/inviteID"
        android:icon="@drawable/ic_action_share"
        android:showAsAction="ifRoom|withText"
        android:title="Invite or Share"/>

</menu>

Manifest code::

<application
        android:name="com.myApp.utilities.AppController"
        android:configChanges="orientation|keyboardHidden"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

Theme i am using::

android:Theme.Holo

Support library ::

android-support-v4.jar

{EDIT}

<?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/searchID"
        android:icon="@drawable/ic_action_search"
        yourapp:showAsAction="never"
        android:title="Search"/>
    <item
        android:id="@+id/featuredID"
        android:icon="@drawable/ic_action_featured"
        yourapp:showAsAction="never"
        android:title="Featured"/>
    <item
        android:id="@+id/dealsID"
        android:icon="@drawable/ic_action_deal"
        yourapp:showAsAction="never"
        android:title="Deals"
        />
    <item
        android:id="@+id/inviteID"
        android:icon="@drawable/ic_action_share"
        yourapp:showAsAction="never"
        android:title="Invite or Share"/>

</menu>

error i am getting

No resource identifier found for attribute 'showAsAction' in package com.myApp

Devrath
  • 42,072
  • 54
  • 195
  • 297
  • If your using support library should you be not using Themes derieved from `Theme.AppCompat`? – Raghunandan Jun 25 '14 at 09:04
  • To make all the menu items appear in overflow menu you have to use "never" value for android:showAsAction. – KunalK Jun 25 '14 at 09:07
  • @Raghunandan ..... Which theme should i need to use ? – Devrath Jun 25 '14 at 09:13
  • @CasperSky what does your activity extend? – Raghunandan Jun 25 '14 at 09:14
  • @Raghunandan ...... my activity extends ....... FragemntActivity – Devrath Jun 25 '14 at 09:15
  • @CasperSky what is your min sdk in manifest is it below 11 coz actionbar is available natively from 11 – Raghunandan Jun 25 '14 at 09:16
  • @Raghunandan .... minimum sdk i am using is 14 but my minimum target in future would be 8 .... so 8 is my min target – Devrath Jun 25 '14 at 09:18
  • @CasperSky extend `ActionBarActivity`. Reference `AppCompat` then do as suggested below in my post. Note : `ActionBatActivity extends FragmentActivity`. use themes dereived from `Theme.AppCompat`. https://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html – Raghunandan Jun 25 '14 at 09:19
  • @CasperSky if its above 11 then there is no need to use AppCompat as actionbar is available natively. Extend Activity and use `android:showAsAction=".."` – Raghunandan Jun 25 '14 at 09:22

2 Answers2

0

Since you are using Support library you need to have your own namespace prefix

 <menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:yourapp="http://schemas.android.com/apk/res-auto" >

Then change this

  android:showAsAction="ifRoom|withText"

to

  yourapp:showAsAction="ifRoom|withText"

Note : If there is not enough space to display items in the actionbar it will appear in the overflow menu. If you have room for few items it appears on the actionbar and the rest in overflow.

Edit:

yourapp:showAsAction="never" 

From the docs

http://developer.android.com/guide/topics/resources/menu-resource.html

 never  Never place this item in the Action Bar.   
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • @ Raghumandan ..... yourapp:showAsAction="ifRoom|withText" .... what is your app means ........... i tried to add like this com.myapp.activities.ActMain:showAsAction="ifRoom|withText" ...please see the edit – Devrath Jun 25 '14 at 09:26
  • @CasperSky that's a custom namespace. copy paste what is there in my post it self. this `com.findmybuffet.activities.ActMain:showAsAction="ifRoom|withText"` should be `yourapp:showAsAction="never"` – Raghunandan Jun 25 '14 at 09:27
  • but i get the error as ------- No resource identifier found for attribute 'showAsAction' ----- when i try the solution – Devrath Jun 25 '14 at 09:47
  • @CasperSky have you read my post. If using Support library you must have your own namepsce prefix `xmlns:yourapp="http://schemas.android.com/apk/res-auto"`. read the post again – Raghunandan Jun 25 '14 at 09:48
  • I followed the instructions .... .....still this error pops up ...any ideas why this happenin – Devrath Jun 25 '14 at 09:52
  • @CasperSky this `xmlns:yourapp="http://schemas.android.com/apk/res-auto"` is not the same as yours is it?. if the namespace is yourapp then `yourapp:showAsAction="never"` – Raghunandan Jun 25 '14 at 09:53
  • This is really a frustrating error .... everything looks correct ...... error: No resource identifier found for attribute 'showAsAction' in package 'com.example.myapp' .... is what i am recieveig ....i must be doing wrong somewhere else let me analyse this – Devrath Jun 25 '14 at 10:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/56262/discussion-between-raghunandan-and-caspersky). – Raghunandan Jun 25 '14 at 10:08
  • @CasperSky join the chat @ http://chat.stackoverflow.com/rooms/56262/discussion-between-raghunandan-and-caspersky – Raghunandan Jun 25 '14 at 10:09
  • yup still not resolved .... does this issue has to do something with http://stackoverflow.com/questions/9739498/android-action-bar-not-showing-overflow link ....please advice – Devrath Jun 27 '14 at 12:42
0
  • Well This was just a workaround to get the answer as below
  • Since i am not having the device to test for the solution to test Raghunandan answer
  • I still believe Raghunandan answer holds good & also sharing what i came to do

Reason for me to test on mobile because:: "device has a menu-button, the overflow-icon won't show."


Code::

@Override
public boolean onOptionsItemSelected(MenuItem item) {   
    ft = getFragmentManager().beginTransaction();

    switch(item.getItemId()) {
    case R.id.descriptionID:
        onItemChangeBackground(1);

        Fragment fragContents = FrgBufDetails.newInstance(buf_off_id);
        ft.replace(R.id.content_frame, fragContents);
        ft.addToBackStack(null);
        ft.commit();

        return true;
    case R.id.MapID:
        onItemChangeBackground(2);

        Fragment fragMap = FrgBufLocation.newInstance(buf_off_id);
        ft.replace(R.id.content_frame, fragMap);
        ft.addToBackStack(null);
        ft.commit();

        return true;
    case R.id.galleryID:
        onItemChangeBackground(3);

        Fragment fragGallery = FrgBufGallery.newInstance(buf_off_id);
        ft.replace(R.id.content_frame, fragGallery);
        ft.addToBackStack(null);
        ft.commit();

        return true;
    case R.id.inviteID:
        onItemChangeBackground(4);

        View title = (View) getActivity()
                    .findViewById(R.id.inviteID);

        //Creating the instance of PopupMenu
        PopupMenu popup = new PopupMenu(getActivity(), title);
        //Inflating the Popup using xml file
        popup.getMenuInflater().inflate(R.menu.actionbar_sort_menu, popup.getMenu());
        popup.show();//showing popup menu

        return true;
    }
    return super.onOptionsItemSelected(item);
}
Devrath
  • 42,072
  • 54
  • 195
  • 297