0

There is an app for API21+ (Material Design).

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    <application
       ...
        android:theme="@style/AppTheme">

styles.xml:

<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">

menu_item_add.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_save"
        android:enabled="false"
        android:icon="@drawable/ic_action_add_entry"
        android:title="@string/action_add"
        app:showAsAction="always"/>
    <item
        android:id="@+id/action_settings"
        android:title="@string/action_settings"
        app:showAsAction="never"/>
</menu>

Menu is inflated inside Activity:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_item_add, menu);
    return true;
}

Android Studio preview show, that it supposed to look like:

enter image description here

But the "Add" is hidden, the menu item is shown along with "Settings" inside popup.

Question:

  • How to make sure the icon is shown?

EDIT:

It seems my problem is similar to this one:

app:showAsAction vs android:showAsAction

However my Activity looks like:

...
public class EntryAddActivity extends Activity {
...

So I don't understand why am I getting message about appcompat.

Community
  • 1
  • 1
0leg
  • 13,464
  • 16
  • 70
  • 94
  • Do you see what you expect to see when you run the app? – azizbekian Apr 20 '17 at 14:20
  • No, the icon is hidden. The "Add" menu item is positioned along with "Settings" inside popup. – 0leg Apr 20 '17 at 14:23
  • Change the namespace prefix on `showAsAction` to `android`. – Mike M. Apr 20 '17 at 14:24
  • So you do not want it to be present there at all? – azizbekian Apr 20 '17 at 14:24
  • @MikeM. it seems the solution is to switch to `android:` namespace. However I've got the message related to `appcompat`. Should I use `Toolbar` instead of `ActionBar` to get rid of `appcompat`? – 0leg Apr 20 '17 at 14:28
  • I don't know what message you mean, but if you're using `Theme.Material`, you can't use any (maybe just most?) appcompat `View`s with it. – Mike M. Apr 20 '17 at 14:31
  • @MikeM. I was able to resolve my problem by using `android:` namespace. If you add your answer, I will mark it as solution. – 0leg Apr 20 '17 at 14:36
  • 1
    Well, that post you just added to your question has the answer, and it's the one I use for duplicates, so I'll just mark this as a duplicate. Thanks, though. Appreciate the offer. Glad you got it working. Cheers! – Mike M. Apr 20 '17 at 14:40

0 Answers0