Last active
December 21, 2015 12:19
-
-
Save daichan4649/6305009 to your computer and use it in GitHub Desktop.
物理メニューキーがある端末でも、ActionBar の overflowメニュー を強制的に表示する (for Android)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application | |
android:name="daichan4649.actionbartest.TestApplication" | |
android:icon="@drawable/ic_launcher" | |
android:label="@string/app_name" | |
android:theme="@style/AppTheme" > | |
<activity | |
android:name="daichan4649.actionbartest.MainActivity" | |
android:label="@string/app_name" > | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
</application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestApplication extends Application { | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
customOverflowMenu(); | |
} | |
private void customOverflowMenu() { | |
try { | |
ViewConfiguration config = ViewConfiguration.get(this); | |
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey"); | |
if (menuKeyField != null) { | |
menuKeyField.setAccessible(true); | |
// 物理メニューキーの有無フラグ | |
// false を設定するとactionbarのoverflowメニューが必ず表示される | |
// true を設定するとactionbarのoverflowメニューは表示されない | |
// 物理メニューキーのない端末 かつ true 設定すると、 | |
// メニュー出せなくなる。詰み。 | |
menuKeyField.setBoolean(config, false); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
物理メニューキーなし、を強制設定する(Applicationのカスタマイズ)
(ActionBar の overflowメニューは物理メニューキーの有無で変わる)