0

I am following the tutorial https://developer.android.com/training/basics/actionbar/adding-buttons.html

Where it says that:

If your app is using the Support Library for compatibility on versions as low as Android 2.1, the showAsAction attribute is not available from the android: namespace. Instead this attribute is provided by the Support Library and you must define your own XML namespace and use that namespace as the attribute prefix. (A custom XML namespace should be based on your app name, but it can be any name you want and is only accessible within the scope of the file in which you declare it.)

So I define following main_activity_actions.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_launcher"
        android:title="temp"
        app:showAsAction="always"/>

    <item
        android:id="@+id/action_settings"
        android:icon="@drawable/ic_launcher"
        android:title="temp"
        app:showAsAction="always"/>

</menu>

And I get following errors:

No resource identifier found for attribute 'showAsAction'

I am using HoloEveryWhere library in my project. Project build target is 19. Manifest has:

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

Any suggestions how to get the custom namespace working?

Adding reference into android-support-v7-appcompat library gives tons of already defined errors:

error: Attribute "actionBarDivider" has already been defined    abc_attrs.xml   /Myapp/HoloEverywhere-master/library/res/values line 71 Android AAPT Problem

Thanks.

Niko
  • 8,093
  • 5
  • 49
  • 85

2 Answers2

0
I tried copying android-support-v7-appcompat.jar under libs folder, but it didn't help

You need to reference AppCompat in your android project instead of adding it as a jar to libs folder.

http://developer.android.com/guide/topics/ui/actionbar.html

Just like how you reference google play services you need to referecen appcompat the same way.

http://developer.android.com/tools/support-library/setup.html

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • Done, but now gettting tons of already defined errors by HoloEveryWhere: error: Attribute "actionBarDivider" has already been defined abc_attrs.xml /myApp/HoloEverywhere-master/library/res/values line 71 Android AAPT Problem – Niko Jan 14 '14 at 06:02
  • @Niko i have not used HoloEveryWhere. http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html. For holo themes you can refer this link – Raghunandan Jan 14 '14 at 06:02
  • @Niko is holoeverywhere dependent on ABS? – Raghunandan Jan 14 '14 at 06:05
  • Yes, but since Holo came in API level 11 and my min target is 8, I cannot use it native way. – Niko Jan 14 '14 at 06:06
  • @Niko read the link i posted full. also i believe holoeverywhere is dependent on ABS. I am not sure though – Raghunandan Jan 14 '14 at 06:07
  • It seems that HoloEveryWhere has some references to ActionBar attrs, since this multiple defined error came up. – Niko Jan 14 '14 at 06:07
  • @Niko try using abs with holo or completely switch to appcompat. this is a suggestion as i am not aware of how to use holoeverywhere. – Raghunandan Jan 14 '14 at 06:09
0

There was no need to use custom namespace in first place. Simply using android namespace android:showAsAction="always" works fine, tested with emulator API level 8 and 2.3x device and 4.4 device.

Niko
  • 8,093
  • 5
  • 49
  • 85
  • Could you please be more specific how is this achieved. Nameliy "showAsAction" does not exist in API level until 11. – f470071 Oct 24 '15 at 20:24