Search code examples
androidactionbarsherlock

ActionBar home button is misplaced in Nexus 5


I'm using ActionBar Sherlock with custom home button. In Nexus 5 home button is misplaced to the right side of the actionbar. You can see it from the images. Has anyone came up to this problem?

Thank you.

enter image description here

Other devices (Such as Nexus 4, Samsung Galaxy S4 etc.)

enter image description here

Nexus 5

For showing custom home button I'm am using

actionBar.setDisplayShowCustomEnabled(true);

Solution

  • I was using RelativeLayout for my custom view and I think it was causing the problem I had. I switched it with LinearLayout and set some properties and my problem solved. These properties are

    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);
    

    But still I didn't understand why it works well with other devices such as Samsung Galaxy S4, Nexus 4 etc. and not working well with Nexus 5 and Nexus 7.

    Before I switched to LinearLayout I tried various way to solve my problem including control for devices and settings margins programmatically.

    For those still insist using RelativeLayout for ActionBarSherlock customView you can use the workaround which I do not recommend.

    if (Build.MODEL.contains("Nexus 5")) {
          LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
          params.setMargins(-150, 0, 0, 0);
          actionBar.setCustomView(v, params);
    }