选项菜单图标未显示

huangapple go评论92阅读模式
英文:

Option menu icon is not showing

问题

这是我在menu.xml中的内容:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/aq"
        android:icon="@drawable/ic_baseline_comment_24"
        android:title="提问" />
    <item
        android:id="@+id/ri"
        android:icon="@drawable/ic_baseline_report_problem_24"
        android:title="报告问题" />
    <item
        android:id="@+id/feed"
        android:icon="@drawable/ic_baseline_feedback_24"
        android:title="反馈" />

    <item
        android:title="更多">
        <menu>
            <item
                android:icon="@drawable/ic_baseline_comment_24"
                android:title="检查" />
        </menu>
    </item>
</menu>

感谢您提前的帮助!

英文:

I'm trying to make an options menu with icons. I'm following this but it's not working. And when I went through previously asked similar questions, they all are pointing towards setting showAsAction always or ifRoom. But I want to make it work while it's set as disabled.

app:showAsAction=&quot;never&quot;

This is what I've in my menu.xml:

&lt;menu xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;&gt;
    &lt;item
        android:id=&quot;@+id/aq&quot;
        android:icon=&quot;@drawable/ic_baseline_comment_24&quot;
        android:title=&quot;Ask Query&quot;/&gt;
    &lt;item
        android:id=&quot;@+id/ri&quot;
        android:icon=&quot;@drawable/ic_baseline_report_problem_24&quot;
        android:title=&quot;Report Issue&quot;/&gt;
    &lt;item
        android:id=&quot;@+id/feed&quot;
        android:icon=&quot;@drawable/ic_baseline_feedback_24&quot;
        android:title=&quot;Feedback&quot;/&gt;
&lt;/menu&gt;

But what I want to do is working with sub menu in the same activity:

 &lt;item
        android:title=&quot;More&quot;&gt;
        &lt;menu&gt;
            &lt;item
                android:icon=&quot;@drawable/ic_baseline_comment_24&quot;
                android:title=&quot;Check&quot;/&gt;
        &lt;/menu&gt;
    &lt;/item&gt;

Thank you in advance for your help!

答案1

得分: 1

<?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:icon="@drawable/ic_baseline_more_vert_24"
        android:title="more"
        app:showAsAction="always">
        <menu>
            <item
                android:id="@+id/aq"
                android:icon="@drawable/ic_baseline_comment_24"
                android:title="Ask Query"/>
            <item
                android:id="@+id/ri"
                android:icon="@drawable/ic_baseline_report_problem_24"
                android:title="Report Issue"/>
            <item
                android:id="@+id/feed"
                android:icon="@drawable/ic_baseline_feedback_24"
                android:title="Feedback"/>
        </menu>
    </item>
</menu>

This article helped me with it.


<details>
<summary>英文:</summary>

<?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:icon="@drawable/ic_baseline_more_vert_24"
android:title="more"
app:showAsAction="always">
<menu>
<item
android:id="@+id/aq"
android:icon="@drawable/ic_baseline_comment_24"
android:title="Ask Query"/>
<item
android:id="@+id/ri"
android:icon="@drawable/ic_baseline_report_problem_24"
android:title="Report Issue"/>
<item
android:id="@+id/feed"
android:icon="@drawable/ic_baseline_feedback_24"
android:title="Feedback"/>
</menu>
</item>
</menu>

Doing it this way helped me achieve what I want. [This][1] article helped me with it.


  [1]: https://www.codingdemos.com/android-options-menu-icon/

</details>



huangapple
  • 本文由 发表于 2020年10月17日 18:08:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/64401280.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定