app:showAsAction与android:showAsAction [英] app:showAsAction vs android:showAsAction
问题描述
我正在构建一个Android应用,并且希望在actionBar上始终显示一个按钮.我遵循了本指南及其他指南,但似乎都没有解决我的问题(尽管我猜它们非常接近...).
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告诉我应该使用带有appCompat ...的app:showAsAction ...".
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
?
推荐答案
这是皮棉规则的文档:
AppCompatResource
摘要:菜单名称空间
AppCompatResource
Summary: Menu namespace
优先级: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操作栏和app:showAsAction
一起使用;或Activity
和android:showAsAction
.
You should use AppCompatActivity
with AppCompat Action bar and app:showAsAction
; or Activity
with android:showAsAction
.
这篇关于app:showAsAction与android:showAsAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!