Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is likely due to the default padding that is applied to the ActionBar in AppCompat. You can remove this padding by setting the content insets to zero:

ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(customView, new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));
    actionBar.setPadding(0, 0, 0, 0);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // Remove elevation/shadow from ActionBar
        actionBar.setElevation(0);
    }
}

Note: customView should be a View that you have already inflated or created for your custom ActionBar layout.