如何使用Actionbarsherlock上&LT强制溢出菜单中的动作条; 4.0设备 [英] how to force overflow menu in Actionbar using Actionbarsherlock on < 4.0 devices

查看:214
本文介绍了如何使用Actionbarsherlock上&LT强制溢出菜单中的动作条; 4.0设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  <一href="http://stackoverflow.com/questions/10509510/actionbarsherlock-holoeverywhere-forcing-overflow">ActionBarSherlock &放大器; HoloEverywhere - 强制溢出

我使用ActionbarSherLock库在pre-姜饼设​​备显示动作条。

I am using ActionbarSherLock library to display Actionbar on pre-Gingerbread devices..

我想在动作条溢出菜单。我寻觅了很多,我都知道,有硬件菜单按钮设备,那么溢出菜单将不显示。

I want Overflow menu on actionbar.. I have searched a lot and i come to know that devices that has hardware Menu Button then Overflow Menu will not display..

和我也看了成ActionbarSherlock示例演示该解决方案,BT我仍不能得到解决方案。

and i also looked into ActionbarSherlock sample demo for that solution,bt still i can't get solution..

我已经创建演示动作条,当上模拟装置,它没有菜单按钮,然后它会显示溢出菜单,但是,如果设备有菜单按钮,然后溢出菜单将不会显示。

I have created demo for actionbar,when emulate on device which has no Menu Button then it will display overflow menu but if device has Menu button then overflow menu will not displaying..

以下是我的配置: -

Following is my Configuration :-

 public class MainActivity extends SherlockActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setTheme(R.style.Theme_Sherlock);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater=getSupportMenuInflater();
        inflater.inflate(R.menu.activity_main, menu);

//        return true;
        return super.onCreateOptionsMenu(menu);
    }
}

清单: -

Manifest :-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demo.menu.actionbar_using_lib"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

 <uses-feature android:name="android.hardware.touchscreen" android:required="false"/>

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock"
     >
    <activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" 
       >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

菜单配置: -

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

<item android:id="@+id/save"
    android:title="@string/menu_save"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="ifRoom|withText"/>

 <item android:id="@+id/setting"
    android:title="@string/menu_settings"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="ifRoom|withText"/>


  <item android:id="@+id/search"
    android:title="@string/menu_search"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="never"/>


   <item android:id="@+id/refresh"
    android:title="@string/menu_refersh"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="never"/>

    <item android:id="@+id/edit"
    android:title="@string/menu_edit"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="never"/>


     <item android:id="@+id/delete"
    android:title="@string/menu_delete"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="never"/>

我要显示溢出menu..so PLZ建议我.. 在此先感谢。

I want to display Overflow menu..so plz Suggest me .. Thanks in Advance..

推荐答案

注意:这个建议,我的不可以使用ForceOverFlow任何读者推荐。这简直是​​上市使其工作(强迫它的工作相当)的可能性。对每一个他自己的。有些人可能希望它和喜欢它。其他人可能不会。

NOTE: With this suggestion, I am not recommending using ForceOverFlow to any reader. This is simply listing a possibility of making it work (forcing it to work rather). To each his own. Some may want it and like it too. Others may not.

我大概猜测,但也许,这可能会为你做它。

I am probably speculating, but perhaps, this may do it for you.

您可以认为这是一个的破解的,但我用它之前强制溢出菜单在我的应用程序之一更早,它的工作原理。

You can think of this a hack, but I used it before to force the Overflow menu in one of my apps earlier and it works.

try {
    ViewConfiguration config = ViewConfiguration.get(MainPage.this);
    Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
    if (menuKeyField != null) {
        menuKeyField.setAccessible(true);
        menuKeyField.setBoolean(config, false);
    }
} catch (Exception e) {
    e.printStackTrace();
}

此外,通过的 MisterSmith 的第二个环节都有各种各样与我在里面回答的解决方案。 Commonsware 的已经放下一些想法有关强制溢出菜单这里:<一href="http://stackoverflow.com/questions/12871850/how-to-control-use-of-overflow-menu-in-ics/12872537#12872537">How为了控制ICS 使用溢出菜单

Also, the second link by MisterSmith has a solution of sorts with my answer in it. Commonsware has put down some thought about forcing the OverFlow menu here: How To Control use of OverFlow Menu in ICS

编辑:虽然打字了这个建议,添加了注释。为了应对这一点,我想指出的杰克·沃顿的拿出.ForceOverFlow主题。我还没有尝试过使用版本的 4.2.0 ,但有一个自定义主题,它只是可能会奏效。如果你绝对必须使用ForceOverFlow,您可能需要使用旧版本。阅读我的答案在这里: http://stackoverflow.com/a/13180285/450534 。事情可能只是使它工作。

While typing out this suggestion, you added a comment. To respond to that, I would like to point out that Jake Wharton took out .ForceOverFlow themes. I haven't tried it with version 4.2.0, but with a custom theme, it just might work. If you absolutely must use ForceOverFlow, you might have to use an older version. Read my answer here: http://stackoverflow.com/a/13180285/450534. Something might just make it work.

编辑2:正如在评论中OP的演示样品APK,事实上,确实ForceOverFlow在的操作栏操作模式。我有一种感觉,检查在github相关的Java文件后,认为这个问题的答案就在于可能在3个Java文件。

EDIT 2: As pointed out by the OP in a comment, the Demos Sample APK, in fact, does ForceOverFlow the action bar in Action Modes. I have a feeling, after checking the relevant Java files on github, that the answer to that lies perhaps in 3 Java files.

  1. 的活动 ActionModes 添加菜单项在一个非常非常规的方式:<一href="https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ActionModes.java">https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ActionModes.java (第53行)
  2. 的ABS库中的 ActionMode 的Java文件:<一href="https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/src/com/actionbarsherlock/view/ActionMode.java">https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/src/com/actionbarsherlock/view/ActionMode.java
  3. 菜单项的Java文件中的ABS图书馆再次一部分:<一href="https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/src/com/actionbarsherlock/view/MenuItem.java">https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/src/com/actionbarsherlock/view/MenuItem.java
  1. The Activity ActionModes adds menu items in a very unconventional manner: https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/demos/src/com/actionbarsherlock/sample/demos/ActionModes.java (Line 53)
  2. The ActionMode Java file in the ABS Library: https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/src/com/actionbarsherlock/view/ActionMode.java
  3. The MenuItem Java file again part of the ABS Library: https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/src/com/actionbarsherlock/view/MenuItem.java

这篇关于如何使用Actionbarsherlock上&LT强制溢出菜单中的动作条; 4.0设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆