I\'m implementing a visual design for an app, and it turns out that the Galaxy S4 misaligns the actionbar home icon, as demonstrated in the screenshot:
This code is pretty self-explanatory. It first checks if the current device is a Samsung Galaxy S4 model, based on the list found here. If it is, it then looks for the relevant Views based on the ActionBar's layout and the home ImageView's relative position in the hierarchy. It then shifts them left by the (positive) offset parameter. It also checks if a Custom View is displayed, and shifts that as well. The only change is to the Views' x coordinates, so it should work with any theme or style.
private static final String SAMSUNG = "SAMSUNG";
private static final String[] S4_MODELS = {
"GT-I9506", "GT-I9505G", "SGH-I337", "SGH-M919",
"SCH-I545", "SPH-L720", "SCH-R970", "GT-I9508",
"SCH-I959", "GT-I9502", "SGH-N045", "SGH-I337M",
"SGH-M919V", "SCH-R970X", "SCH-R970C"
};
private void adjustGalaxyS4(int offset)
{
if (isGalaxyS4())
shiftHomeView(offset);
}
private boolean isGalaxyS4()
{
String manufacturer = Build.MANUFACTURER.toUpperCase();
String model = Build.MODEL.toUpperCase();
if (SAMSUNG.equals(manufacturer) && !TextUtils.isEmpty(model))
{
for (String m : S4_MODELS)
if (model.contains(m))
return true;
}
return false;
}
private void shiftHomeView(float offset)
{
try
{
View grandParentView = (View) ((View) findViewById(android.R.id.home).getParent()).getParent();
View upView = ((ViewGroup) ((ViewGroup) grandParentView).getChildAt(0)).getChildAt(0);
grandParentView.setX(grandParentView.getX() - offset);
upView.setX(upView.getX() + offset);
if ((getActionBar().getDisplayOptions() & ActionBar.DISPLAY_SHOW_CUSTOM) != 0)
getActionBar().getCustomView().setX(getActionBar().getCustomView().getX() - offset);
}
catch (Exception e)
{
// Fail silently
}
}