Android - want to show 3-dots menu on ICS

2019-08-04 05:24发布

问题:

I want to show the 3-dot overflow menu key (next to the RecentApp virtual key) when building my app with

android:targetSdkVersion="15"

Here is my story. My app includes two lib projects (only jars + res no source), lib-a is using menu; when the app was built with target-sdk=10, works well, the 3-dot icon shows up next to RecentApp key on system navigation bar. Now lib-b got upgraded, I HAVE to build the app with target-sdk=15, but this makes lib-a UI menu disappear. I want lib-a to have menu as before.

I checked these posts, which are very helpful,

Android Action Bar menu not showing when target sdk version is greater than 10

Android theme, fullscreen and the action bar

I can neither apply ActionBarSherlock nor set target-sdk to 10. So I am wondering if using old theme (not holo theme) will help. I created a theme, derives from [android.Theme], apply to all activities in lib-a (in app's manifest xml), but no luck.

So my question is, will theme be able to solve the problem?

回答1:

I think you simply can't. That "overflow menu" in system bar is there for legacy reasons, and it shows up if and only if a legacy app (target sdk<11) runs on a device with the virtual system bar. It's simply not intended to show up when targeting higher versions.



回答2:

No you cannot do it. You might download an earlier version of actionBarSherlock (ie 4.1.0) where absForceOverflow was an existing method, so this will force your 3-dot menu to every system up to 1.6, but this could cause you issues (like phones with hardware keyboard etc).

I stumbled this issue couple of weeks ago and I solved this with a workaround: a simple menu icon into the actionbar (the 3-dot icon), and if you click on it a custom dialog appears which looks just like the original menu (you can programmatically place it to the right place, since you know that the default height of the bar (e.g. 48dp on hdpi phones) ).

Hope this helps.



回答3:

Yes you can you just need to change targetVersion from your onCreate method like this :

@Override
public void onCreate(Bundle savedInstanceState) {
    getApplicationInfo().targetSdkVersion = 10; // To enable the 3-dot menu call this code before super.OnCreate
    super.onCreate(savedInstanceState); 
}

Tested on Android 4.x.x and Android 3.0