Skip to content

Instantly share code, notes, and snippets.

@messenger63
messenger63 / gist:c5b59f1d2340fdfe3d01
Created December 18, 2014 10:32
Move drawer to top (above ActionBar).
//call in onCreate()
private void moveDrawerToTop() {
DrawerLayout drawer = (DrawerLayout) layoutInflater.inflate(R.layout.left_drawer, null); // "null" is important.
// HACK: "steal" the first child of left_drawer view
ViewGroup decor = (ViewGroup) getWindow().getDecorView();
View child = decor.getChildAt(0);
decor.removeView(child);
LinearLayout container = (LinearLayout) drawer.findViewById(R.id.drawer_content); // This is the container we defined just now.
container.addView(child, 0);
@messenger63
messenger63 / gist:e3f838bc100b5790ef48
Created December 18, 2014 10:29
Customize (hide) arrow from dropdown list in ActionBar
AndroidManifest.xml:
android:theme="@style/MyAppTheme"
Styles.xml:
<style name="MyAppTheme" parent="@style/Theme.AppCompat.Light">
<item name="actionDropDownStyle">@style/DropDownNav.Example</item>
</style>
<style name="DropDownNav.Example" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
<item name="android:background">@android:color/transparent</item>
@messenger63
messenger63 / gist:3528d2d7bba7be9ea311
Created December 3, 2014 09:49
Force show 3 dot overflow menu item on ActionBar via menu.xml
<item
android:id="@+id/menu_overflow"
android:title="Overflow"
android:icon="@android:drawable/ic_menu_more"
android:orderInCategory="1"
app:showAsAction="always">
<menu>
<item android:id="@+id/item1"
android:icon="@drawable/icon1"
android:title="title1"
@messenger63
messenger63 / gist:d3033fbbeea23ad50b71
Created December 3, 2014 09:47
Force show 3 dot overflow menu item on ActionBar
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}