appcompat 21 logo as back button

2019-02-19 03:38发布

After update sdk to 21 version logo doesn't display. I display logo using following code:

actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setIcon(R.drawable.ic_launcher);

The code looks: http://i.stack.imgur.com/fAWIx.png

enter image description here

This code:

actionBar.setDisplayShowHomeEnabled(true);
actionBar.setIcon(R.drawable.ic_launcher);

Looks: http://i.stack.imgur.com/hkYqa.png

enter image description here

This code:

actionBar.setDisplayHomeAsUpEnabled(true);

Looks: http://i.stack.imgur.com/Ssw2A.png

enter image description here

My logo doesn't display as back button.

How me make old style as here? http://i.stack.imgur.com/BKOz4.png

Note: Sorry, I didn't notice similar questions. =(

2条回答
老娘就宠你
2楼-- · 2019-02-19 04:00

Per the Toolbar documentation:

  • A title and subtitle. The title should be a signpost for the Toolbar's current position in the navigation hierarchy and the content contained there. The subtitle, if present should indicate any extended information about the current content. If an app uses a logo image it should strongly consider omitting a title and subtitle.

In modern Android UIs developers should lean more on a visually distinct color scheme for toolbars than on their application icon. The use of application icon plus title as a standard layout is discouraged on API 21 devices and newer.

However, if you want an application icon, setLogo() is indeed the correct method.

查看更多
我想做一个坏孩纸
3楼-- · 2019-02-19 04:10

Here's what worked for me if using an icon

actionBar.setIcon(R.drawable.ic_app_icon);
actionBar.setDisplayShowHomeEnabled(true);

Or, if you want a wider logo

actionBar.setLogo(R.drawable.ic_app_logo);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);

查看更多
登录 后发表回答