I'm trying to use the Icons of the Sherlock Actionbar in my menu XML-File but I can't figure the right namespace out.
I tried com.sherlock and com.sherlock.R but nothing seemed to work. I couldn't find documentation on that either!
That's what I tried:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:sherlock="http://schemas.android.com/apk/res/com.actionbarsherlock.R" >
<item
android:id="#+id/action_refresh"
android:orderInCategory="99"
android:showAsAction="ifRoom"
android:icon="#sherlock:drawable/action_refresh"
android:title="#string/action_refresh"
/>
</menu>
But that just fails with an error message that the icon couldn' be found.
Error: No resource found that matches the given name (at 'icon' with value '#sherlock:drawable/action_refresh')
Any ideas how to get the correct namespace?
you no need to put the namespace. use the below code
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_refresh"
android:orderInCategory="99"
android:showAsAction="ifRoom"
android:icon="#drawable/action_refresh"
android:title="#string/action_refresh"
/>
</menu>
Related
i'm try to apply actionbar in my android, i copied a menu xml from another app to current app (/res/layout/menu/actionbarmenu.xml)
here is the code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/media_play"
android:icon="#android:drawable/ic_media_play"
android:title="#string/media_play"
android:showAsAction="ifRoom|withText"/>
<item android:id="#+id/media_pause"
android:icon="#android:drawable/ic_media_pause"
android:title="#string/media_pause"
android:showAsAction="ifRoom|withText"/>
<item android:id="#+id/media_previous"
android:icon="#android:drawable/ic_media_previous"
android:title="#string/media_previous"
android:showAsAction="ifRoom" />
<item android:id="#+id/media_next"
android:icon="#android:drawable/ic_media_next"
android:title="#string/media_next"
android:showAsAction="ifRoom">
</item>
</menu>
In every line "ifRoom|withText", there is a red underline appear and with yellow box :
Should use app:showAsAction with the appcompat library with
xmlns:app="http://schemas.android.com/apk/res/auto"
Anyone know what is the problem?
You should use app namespace for menu which is part of appcompat.
<?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/media_play"
android:icon="#android:drawable/ic_media_play"
android:title="#string/media_play"
app:showAsAction="ifRoom|withText"/>
<item android:id="#+id/media_pause"
android:icon="#android:drawable/ic_media_pause"
android:title="#string/media_pause"
app:showAsAction="ifRoom|withText"/>
<item android:id="#+id/media_previous"
android:icon="#android:drawable/ic_media_previous"
android:title="#string/media_previous"
app:showAsAction="ifRoom" />
<item android:id="#+id/media_next"
android:icon="#android:drawable/ic_media_next"
android:title="#string/media_next"
app:showAsAction="ifRoom">
</item> </menu>
The android:showAsAction has been added in API 11 and your app has probably lower minimum API level. You can use the AppCompat library which will provide this parameter and its desired behavior, however, to reffer the AppCompat parameter you have to call it within the right XML namespace.
The namespace is included by the suggested code added to root <menu> tag
xmlns:app="http://schemas.android.com/apk/res/auto"
and then you can add app:showAsAction to your <item> tags
Previously, before using AppCompat, I was using SherlockActionBar to support Android 2.3.
The following menu works just perfect under SherlockActionBar
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_browser"
android:title="#string/menu_browser"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
android:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
However, even since migrating to AppCompat, I realize the above menu doesn't work. I need to use app namespace, in order to make it work.
<?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/menu_browser"
android:title="#string/menu_browser"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarBrowserIcon"/>
<item
android:id="#+id/menu_share"
android:title="#string/menu_share"
app:showAsAction="ifRoom"
android:icon="?attr/actionBarShareIcon"/>
</menu>
Why is this so? What is the difference comparing to SherlockActionBar, which makes app namespace unnecessary?
Attributes provided by libraries (or by the app itself) are suppose to be namespaced in order to avoid conflicts/collisions.
ActionBarSherlock masks this behavior by naming the attribute android:showAsAction. (As opposed to a showAsAction attribute in the android namespace): https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock/res/values/abs__attrs.xml
I am very new to android development with eclipse, and I encounter dozen of errors and problems. Here is the next one:
I am following a tutorial to learn android development on eclipse. I was following the example here to include actions xml (file res/menu/main_activity_actions.xml):
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" />
</menu>
The following line is marked with the error given in the title:
android:title="#string/action_search"
although I have added the following line to res/values/strings.xml:
<string name="action_search">SEARCH</string>
I even cleared the project. What is wrong now?
Addendum:
Not sure if this is related, the cause of my problem or caused by my problem: Every variable reference to 'R' has an error: 'R cannot be resolved to a variable'.
I have used AppCompact for implenting the action bar. Below is my menu xml code, please try with the code
<item
android:id="#+id/action_search"
android:icon="#drawable/icon_search"
android:title="#string/search"
yourapp:actionViewClass="android.support.v7.widget.SearchView"
yourapp:showAsAction="ifRoom|collapseActionView"/>
Rest of your xml view...
All, Forgive me I just began to learn development of Android, It is the first time I used the ActionBar in my Android application. Firstly.
I was following the tutorial to add the resource of ActionBar to project. But the IDE alert me the resource can't be found. please help to review my current setup. thanks.
I had downloaded and upziped all the Icons. and copy all the icons under the res/drawable folder.
and I add a xml file named main_activity_actions.xml under the folder res/menu which content shows below.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
<item android:id="#+id/action_search"
android:icon="#drawable/Core_Icons/unstyled/hdpi/ic_action_search"
android:title="#string/action_search"
android:showAsAction="ifRoom" />
<!-- Settings, should always be in the overflow -->
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="never" />
</menu>
Could someone please tell me why IDE can't find the icon ic_action_search.png? thanks.
Unfortunately the resource folders do not support directory hierarchies (sub-folders), so you will need to move all icons to the parent folder (drawable).
Then reference it like this: android:icon="#drawable/ic_action_search"
https://code.google.com/p/android/issues/detail?id=2018
I've started using the ActionBar coming with the AppCompat library. But any action I add to this, shows up in the overflow menu. I'm pretty sure I've skipped something, but I don't know at all. Here's my menu file:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/connect_plus"
android:icon="#drawable/ic_google_plus"
android:title="Connect to Google+"
android:showAsAction="always"
android:titleCondensed="Connect to Google+">
</item>
</menu>
And any configuration in the onCreate method from an activity extending from ActionBarActivity:
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
Did I miss something?
Did I miss something?
Yes.
You need to use your own namespace:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<item
android:id="#+id/connect_plus"
android:icon="#drawable/ic_google_plus"
android:title="Connect to Google+"
yourapp:showAsAction="always"
android:titleCondensed="Connect to Google+">
</item>
</menu>
as is shown in the documentation.