There is an activity which has no menu item. So I want to hide the menu button. Is there any way to achieve that? Thanks
How do we hide the menu on toolbar in one fragment? When you click the show button to open a fragment, you can see the fragment menu items ordered before activity menu items. This is because of the menu item's android:orderInCategory attribute value. When you click the hide button to hide the fragment.
I figured out how this can be done. In your AndroidManifest.xml, you need to specify something like the following:
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="14" />
Basically, minSdkVersion
is the minimum Android SDK version that you application supports (in my case, 2.2) and targetSdkVersion
is the version you're "targetting" (i.e. your "preferred" version - in my case, that's 4.0)
By default, targetSdkVersion
is the same as minSdkVersion
, and if you leave that pre-Honeycomb, you're basically telling Android that your app is "legacy" and it'll always show the menu button.
If you make targetSdkVersion
post-Honeycomb, then the menu button will only be shown if you actually have menu items defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With