showAsAction = “always” is ignored in Toolbar

前端 未结 2 1434
独厮守ぢ
独厮守ぢ 2020-12-19 11:37

After switching to toolbar there is a problem with menu icons. Although I set for a menu item android:showAsAction=\"always\" it does not show the icon, I can only find it c

相关标签:
2条回答
  • 2020-12-19 11:57

    Replace android:showAsAction with app:showAsAction. You will also need to add xmlns:app="http://schemas.android.com/apk/res-auto" alongside your existing xmlns item in your root element.

    0 讨论(0)
  • 2020-12-19 12:10

    With AppCompat there is a little change. If you are running lint it will complain about it. Type this:

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/someId"
        android:title="@string/someText"
        app:showAsAction="always"/>
    </menu>
    

    You need to declare the "app" namespace and reference it.

    0 讨论(0)
提交回复
热议问题