Question

Im building my top menu using the following code:

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


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle presses on the action bar items
        switch (item.getItemId()) {
            case R.id.map_view:
                Toast.makeText(getApplicationContext(), "Map view pressed",
                        Toast.LENGTH_LONG).show();
                return true;
            case R.id.camera_only:
                   Toast.makeText(getApplicationContext(), "Camera only pressed",
                    Toast.LENGTH_LONG).show();
                    return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

menu_view.xml

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

    <item
    android:id="@+id/dots_menu"
    android:icon="@drawable/ic_action_overflow"
    android:showAsAction="always"
    android:title="@string/dots_menu">
    <menu>
        <item
            android:id="@+id/map_view"
            android:icon="@drawable/ic_action_map"
            android:showAsAction="never"
            android:title="@string/map" />
        <item
            android:id="@+id/camera_only"
            android:showAsAction="never"
            android:title="@string/camera_only"/>
   </menu>
</item>

</menu>

It happens that in my main activity i want to use this menu on top, but the menu appers transparent. Im using a fragment to display a full-screen map (google maps api v2), but then i can see the map under the top menu. I would like this fragment to "auto-resize" under the menu.

How can i set menu always on top of every activity?

Was it helpful?

Solution

So, i found out what my problem was!

in styles.xml file:

<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
       parent="@android:style/Theme.Holo">
      <item name="android:windowActionBarOverlay">true</item>

</style> </resources>

i just needed to change the attribute windowActionBarOverlay to false, and it makes automatically the resize for the activity content.

For more details, here is the documentation

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