I have an options menu in my app, which has more than six items, so there is a "More" item that brings up the overflow menu. The menu is posted by the default menu triggers, and a custom trigger that invokes Activity.openOptionsMenu().
The menu itself is built from this resource file:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/mi_copy"
android:title="Copy"
android:icon="#drawable/copy"/>
<item android:id="#+id/mi_paste"
android:title="Paste"
android:icon="#drawable/paste"/>
<item android:id="#+id/mi_preferences"
android:title="Preferences"
android:icon="#android:drawable/ic_menu_preferences"/>
<item android:id="#+id/mi_flip_calc_printout"
android:title="Print-Out"
android:icon="#drawable/printer"/>
<item android:id="#+id/mi_clear_printout"
android:title="Clear Print-Out"
android:icon="#android:drawable/ic_menu_close_clear_cancel"/>
<item android:id="#+id/mi_about"
android:title="About Free42"/>
<item android:id="#+id/mi_import"
android:title="Import Programs"/>
<item android:id="#+id/mi_export"
android:title="Export Programs"/>
</menu>
So far, so good. The menu and the Java logic that creates and posts it has worked for years, but now I'm changing the targetSdkVersion from API level 8 to 26, per the latest Play requirements, and now all of a sudden, the menu items in the overflow menu have become invisible.
The overflow menu still posts, and it still has the correct size, and the menu items still work. You just can't see them any more: the whole menu is solid black now, which is the normal background color; the menu item text is missing.
The phone on which I'm testing is a Motorola G5 running Android 8.1.0. This is the only device I have available for testing with API 26 at the moment, at least until I figure out how to create an AVD with API >= 26.
N.B. In the Android simulator with an API level 8 image, the overflow menu still looks fine. It used to look fine on the Moto G5 as well, before I targeted API 26. If I change the target back to 8, the overflow menu works again.
Any thoughts on what I could do to fix this? My Google skills aren't working on this one... Any ideas would be most welcome!
I added this style file as res/values/styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Free42Theme" parent="android:style/Theme.NoTitleBar">
<item name="android:itemBackground">#android:color/white</item>
</style>
<style name="Free42Theme.Fullscreen" parent="android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:itemBackground">#android:color/white</item>
</style>
</resources>
The first is the default theme, specified by changing the android:theme attribute on the Activity from #android:style/Theme.NoTitleBar to #style/Free42Theme in AndroidManifest.xml; the second is the full-screen theme, set in the Java code, by changing the setTheme(android.R.style.Theme_NoTitleBar_Fullscreen) call to setTheme(R.style.Free42Theme_Fullscreen).
This changes the background of the overflow menu to white, making the black item text visible, verified on my G5. Running in the simulator with Android 2.2 (API level 8), the appearance is unchanged since the background was white there from the start.
Many thanks to SteelToe for getting me on the right track!
Related
I was working on an app with some pages in it. During my development phase I always tested my code with an Android Virtual Device (API: 22, Android 5.1), after publishing the app I downloaded it to my phone (API: 26, Android 8.0) and faced it with differences which i was not expecting. The source of problems was the toolbar.
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" with this code I set both title's and back button's color to white however title's color was grayish and all letters were changed to uppercase.
In my sub-activities I overrode onOptionsItemSelected method and
Toolbar toolbar = findViewById(R.id.toolbar);
setActionBar(toolbar);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowHomeEnabled(true);
used these methods to use back button. However, only one of the back buttons worked, others were useless.
Most probably its because of version difference, but couldn't find the proper solution.
Please try Below code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Custom.Dark"parent="Theme.AppCompat.NoActionBar">
<item name="actionBarStyle">#style/Theme.AppCompat</item>
</style>
<style name="Theme.Custom.Light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionBarStyle">#style/Custom.Dark</item>
</style>
</resources>
After creating a menu for my action bar. The little arrow doesn't appear next to the share icon and I'm not sure why this has happened or if it's intentional based on my code.
<?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_info"
android:title="#string/information"
android:icon="#android:drawable/ic_menu_info_details"
app:showAsAction="ifRoom"/>
<item android:id="#+id/action_share"
android:title="#string/menuitem_share"
android:icon="#android:drawable/ic_menu_share"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
app:showAsAction="ifRoom"/>
<item android:id="#+id/action_preferences"
android:title="#string/menuitem_preferences"
app:showAsAction="never"/>
</menu>
After viewing images of similar menus online, I noticed that little arrow (in this screenshot).
How can that little arrow be added to the share icon?
As far as I know, every new project you create in Android Studio uses the Material design (introduced with Android 5.0 Lollipop) with AppCompat themes. It is designed to show up on every compatible device thanks to Support Library (even on pre-Lollipop devices), and ActionBar menu items created when you are using Support Library looks like on the first image.
As far as I also know, I've seen this kind of arrowed Share button on the second image last time on a 4.x device. So I think you could re-create this kind of Share button if you would not use any theme and let your pre-Lollipop device to do the work with the ActionBar.
I've tried to recreate this behaviour by your code above, without luck. But then I opened the ApiDemos app which is on every Android Studio emulator image and shows a lot of functions built up in Android, for example ActionBar functions. There I saw that Share button looks differently on different API levels.
Android 4.4 KitKat:
Android 5.0 Lollipop:
Faced a strange options menu behavior on Android M.
Menu shadow is implemented with 9 patch and works perfect on previous Android versions.
But on sixth Android it appears only for a while.
Also it look like it appears for a while during close animation.
Menu style is below:
<style name="PopupMenu" parent="Widget.AppCompat.Light.PopupMenu">
<item name="android:popupBackground">#drawable/shadow</item>
<item name="android:overlapAnchor">true</item>
</style>
Will be thankful for any help in fixing this shadows visibility issue.
Try to remove background from DropDown ListView style
I have tried setting the:
android:showAsAction=".."
to every one of these:
ifRoom, never, withText, always, collapseActionView
but I always got the same result, which is not having any buttons on the action bar, so I have to press the 'menu' button.
Here is a picture of the menu now :
<item android:id="#+id/smth1"
android:title="#string/smth1"
android:showAsAction="always"
android:orderInCategory="1" />
I have even tried adding this:
android:uiOptions="splitActionBarWhenNarrow"
into application manifest file, but with no positive result (nothing changed).
I have tried running it on various kind of APIs (14, 16, 17, 19), but with the same result.
If my question seems to be unclear, here is a picture of a menu, which I would like to have:
Thanks for any help.
You need to use the compatibility namespace (see here)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_add_size"
android:title="#string/menu_add_item"
android:icon="#android:drawable/ic_menu_add"
app:showAsAction="always"/>
</menu>
Once you're using that you can use as many menu buttons as will fit. You're no longer limited to just two buttons + overflow showing.
You maybe just don't have enough space, you should first remove the title from your Activity by adding this to your onCreate method:
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Then you can see here that the maximum number of icons you can display is directly linked to the width of your screen, on small phones you will only be able to see 2 icons in the ActionBar.
After integrating the ActionBarSherlock in my android app I noticed that the dropdown menu that drops when the user hits the overflow button differs between 2.* and 4.*.
I have successfully customize this dropdown menu for 2.* with the right colours, but the dropdown menu in 4.* is displayed with white color andblack text and nothing that I do seems to modify this menu.
Do I need to do anything special to customize this dropdown menu in 4.*? it is even possible?
Thanks
When you add a style for ABS, you must be sure to also include the proper Android tags. E.g.
Not just
<item name="actionBarStyle">#style/ActionBar</item>
But
<item name="actionBarStyle">#style/ActionBar</item>
<item name="android:actionBarStyle">#style/ActionBar</item>
The former only controls ABS, and the library uses the standard Action Bar on 4.x.