Android编程问题解决之Error should use android showAsAction

Android编程问题解决之Error should use android showAsAction when not using support library

在编写关于menus.xml文件时,可能会遇到错误提示Error should use android showAsAction when not using support library,这个问题是怎么出现呢?

从Android1.0到Android6.0增加了很多功能,为了让低版本的android系统可以使用最新的添加的功能,Android操作系统的编写者在最新的操作系统中会提供一个包(例如com.android.support:appcompat-v7:23.3.0就是Android6.0的低版本支持包),这个包用于让低版本的adnroid系统可以使用最新的功能。

如果在使用了包的android项目中使用了低版本支持包,在定义menu资源时应该使用如下形式

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:yourapp="http://schemas.android.com/apk/res-auto" > 
<item android:id="@+id/action_search"  
android:icon="@drawable/ic_action_search" 
android:title="@string/action_search"
yourapp:showAsAction="ifRoom"  />     
</menu>

其中yourapp:showAsAction=”ifRoom”就是低版本支持包中提供的内容。

如果在项目中没有使用低版本支持包,在定义menu资源时应该使用如下形式

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:id="@+id/action_search"  
android:icon="@drawable/ic_action_search" 
android:title="@string/action_search"
android:showAsAction="ifRoom"  />     
</menu>

如果在编程中出现Error should use android showAsAction when not using support library错误只要按照下面的方法修改即可
1. 如果需要低版本支持包使用yourapp:showAsAction=”ifRoom” 方式
2. 如果不需要低版本支持包将低版本依赖去掉即可

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    //compile 'com.android.support:appcompat-v7:23.3.0'
}

版权声明:原创作品版权归作者所有,转载请注明出处,未经允许禁止私自印刷及出版。一经发现作者将依法追究其法律责任。

与我联:QQ群539225664


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值