Question

I'm having some problems adding my own icons to the action bar. The documentation states I should be a custom namespace like this:

yourapp:showAsAction="ifRoom"

but when I replace 'android' with 'com.example.appname' or even just 'appname' Android Studio give a. 'namespace out of bound error'

Should I be making changes to one of the schemes if so where/how?

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

    <item android:id="@+id/action_new"
        android:icon="@drawable/ic_action_new"
        android:title="@string/action_new"
        android:showAsAction="ifRoom" />

    <item android:id="@+id/action_search"
       android:icon="@drawable/ic_action_search"
       android:title="@string/action_search"
       android:showAsAction="ifRoom" />

   <item android:id="@+id/action_settings"
        android:title="@string/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never" />
</menu>
Was it helpful?

Solution

You don't replace it with your application name but with the actual string "yourapp", since you define it right here:

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

So you don't use your application name but in this case literally yourapp:showAsAction="ifRoom"

Side note: you can name it something else, for example:

xmlns:someapp="http://schemas.android.com/apk/res-auto

Then the usage would be someapp:showAsAction="ifRoom"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top