gpt4 book ai didi

android - 应该使用android :showAsAction when not using the appcompat library

转载 作者:IT老高 更新时间:2023-10-28 23:29:36 27 4
gpt4 key购买 nike

我有一个奇怪的问题,我在我的 android 应用程序中使用 menu.xml 文件,如下所示:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:compat="http://schemas.android.com/apk/res-auto" >

<item
android:id="@+id/action_refresh"
android:orderInCategory="100"
android:title="@string/action_refresh"
android:icon="@drawable/toc"
compat:showAsAction="always"/>
</menu>

它运行良好,但几天前我将我的 eclipse 更新到最后一个版本,之后,app:showAsAction="always"显示错误:

Should use android:showAsAction when not using the appcompat library and after that my action bar icons was moved to the overflow bar and not showing the in the action bar at all.

无论如何,appcompat 库是我的基本样式的父级。我应该怎么做才能解决这个问题?

最佳答案

你需要做三件事-

  1. 添加这三样东西xmlns:tools="schemas.android.com/tools"
    tools:context="com.example.sample.YourActivity" xmlns:yourapp="http://schemas.android.com/apk/res-auto"
    给您的<menu>标记

    连同通常的 xmlns:android="http://schemas.android.com/apk/res/android"

  2. 添加 yourapp:showAsAction="ifRoom"给您的<item> .

  3. 最后,通过 Project -> Clean...

  4. 清理您的项目

最后一步为我解决了这个问题。只需清理项目(它们有时会变得很脏)

这是最终代码的样子:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="schemas.android.com/tools"
tools:context="com.example.sample.YourActivity"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >

<item
android:id="@+id/action_share"
android:orderInCategory="100"
android:title="Share"
android:icon="@drawable/ic_share_white"
yourapp:showAsAction="ifRoom" />

</menu>

关于android - 应该使用android :showAsAction when not using the appcompat library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26889976/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com