应用程序:showAsAction 与 android:showAsAction [英] app:showAsAction vs android:showAsAction

查看:21
本文介绍了应用程序:showAsAction 与 android:showAsAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Android 应用程序,并希望在 actionBar 上有一个始终可见的按钮.我遵循了 this 指南和其他指南,但似乎没有一个解决我的问题(虽然我猜他们非常接近......).

I am building an Android app and want to have a button always visible on the actionBar. I followed this guide and others, but none of them seem to solve my problem (although they are very close I guess...).

我有app"包并使用 app:showAsAction="always".没有显示错误,但栏上也没有按钮.当我将其更改为 android:showAsAction="always" 时,按钮出现在栏上,但 AndroidStudio 告诉我应该选择app:showAsAction with appCompat...".

I have the package "app" and use app:showAsAction="always". No error is shown, but no button on the bar as well. When I change it to android:showAsAction="always" the button appears on the bar, but AndroidStudio tells me I should go for "app:showAsAction with appCompat...".

我有一个带有 parent="@android:style/Theme.Holo.Light.DarkActionBar"> 和栏本身的自定义主题:parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">.

I have a custom theme with parent="@android:style/Theme.Holo.Light.DarkActionBar"> and for the bar itself: parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">.

我应该改变一些东西并让 app:showAsAction 工作,还是忽略 AndroidStudio 错误消息并选择 android:showAsAction?

Should I change something and get app:showAsAction working, or ignore AndroidStudio error message and go for android:showAsAction?

推荐答案

这是 lint 规则的文档:

This is the documentation of the lint rule:

总结:菜单命名空间

优先级:5/10

严重性:错误

类别:可用性

使用 appcompat 库时,菜单资源应参考app: 命名空间中的 showAsAction,而不是 android: 命名空间.

When using the appcompat library, menu resources should refer to the showAsAction in the app: namespace, not the android: namespace.

同样,当不使用 appcompat 库时,您应该使用android:showAsAction 属性.

Similarly, when not using the appcompat library, you should be using the android:showAsAction attribute.

我认为问题在于您混合了 Framework Activity 和 AppCompat 菜单.

I think the problem is that you are mixing Framework Activity and AppCompat menu.

您应该将 AppCompatActivity 与 AppCompat Action bar 和 app:showAsAction 一起使用;或 Activityandroid:showAsAction.

You should use AppCompatActivity with AppCompat Action bar and app:showAsAction; or Activity with android:showAsAction.

这篇关于应用程序:showAsAction 与 android:showAsAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆