I'd like to increase the height of a single MenuItem
inside a NavigationView
.
I am trying to put a Google MapFragment
inside the item's actionLayout
, as shown below, but I want the height of the map to be larger.
Any ideas?
Note:
- I want to utilise the standard menu layout of the NavigationView (I'd prefer not to have to implement a whole custom menu layout as using this answer).
- I don't want to change the height of all items like this answer, only the map item.
activity_main_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:showIn="navigation_view">
...
<item
android:id="@+id/nav_map"
app:showAsAction="always"
android:title="@string/nav_map"
app:actionLayout="@layout/fragment_map" />
...
</menu>
fragment_map.xml
Adjusting android:layout_height
here has no effect.
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/nav_map_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:mapType="normal"
map:liteMode="true"/>
In Activity.onCreate(...)
in MainActivity.kt
Setting the height on the action view has no effect here.
val mapItem = nav.menu.findItem(R.id.nav_map)
// Has no effect: trying to set height to 128dp
mapItem.actionView.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 128)
// Hack: hide title
mapItem.title = null
val mapView = supportFragmentManager.findFragmentById(R.id.nav_map_fragment) as SupportMapFragment
mapView.getMapAsync { map ->
...
}