ActionBar home button is misplaced in Nexus 5

末鹿安然 提交于 2019-12-13 20:11:57

问题


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.

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

Nexus 5

For showing custom home button I'm am using

actionBar.setDisplayShowCustomEnabled(true);

回答1:


Hope, you have added below lines

actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);

ActionBar Sherlock is depreciated change it with appcompart




回答2:


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);
}



回答3:


Maybe this will work. Try

    View homeIcon = findViewById(android.R.id.home);
    ((View) homeIcon.getParent()).setVisibility(View.GONE);
    getSupportActionBar().setTitle("");


来源:https://stackoverflow.com/questions/23311240/actionbar-home-button-is-misplaced-in-nexus-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!