android:showAsAction="never"报错

android studio目录下没有menu(eclipse中有),怎么解决?

在res 下面创建 一个文件夹menu, 和 drawable 是同级别的。 menu 只是单纯一个文件夹目录,不同于 res 、 assets这样的文件目录。

在新建的menu目录下的xml文件中有android:showAsAction=”never”报错

如下图所示:这里写图片描述

解决办法是:添加此命名空间 xmlns:app=”http://schemas.android.com/apk/res-auto” ,使用app:showAsAction代替android:showAsAction。

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Android Apps for Absolute Beginners: Covering Android 7 by Wallace Jackson English | 6 Apr. 2017 | ISBN: 1484222679 | 484 Pages | PDF | 26.76 MB Get your first Android apps up and running with the help of plain English and practical examples. If you have a great idea for an Android app, but have never programmed before, then this book is for you. Android Apps for Absolute Beginners cuts through the fog of jargon and mystery that surrounds Android app development, and gives you simple, step-by-step instructions to get you started. This book teaches Android application development in language anyone can understand, giving you the best possible start in Android development. It provides clean, straightforward examples that make learning easy, allowing you to pick up the concepts without fuss. It offers clear code descriptions and layout so that you can get your apps running as soon as possible Although this book covers what's new in Android 7, it is also backwards compatible to cover some of the previous Android releases. What You'll Learn Download, install, and configure the latest software needed for Android app development Work efficiently using an integrated development environment (IDE) Build useful, attractive applications and get them working immediately Create apps with ease using XML markup and drag-and-drop graphical layout editors Use new media and graphics to skin your app so that it has maximum appeal Create advanced apps combining XML, Java and new media content Who This Book Is For If you have a great idea for an Android app, but have never programmed before, then this book is for you. You don’t need to have any previous computer programming skills ― as long as you have a desire to learn and you know which end of the mouse is which, the world of Android apps development awaits.
要给这段代码所代表的按钮添加一个更换 app 背景的功能,您可以按照以下步骤进行操作: 1. 打开您的 Activity 类文件,并在 `onCreateOptionsMenu()` 方法中找到这个菜单项对应的代码,通常是类似下面的代码: ```java @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.your_menu, menu); return true; } ``` 2. 在 `onOptionsItemSelected()` 方法中,找到这个菜单项的点击事件对应的代码,通常是类似下面的代码: ```java @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.myButton) { // 处理点击事件 return true; } return super.onOptionsItemSelected(item); } ``` 3. 在点击事件处理代码中,添加更换 app 背景的逻辑。例如,您可以使用 `getWindow()` 方法获取当前 Activity 的窗口对象,然后使用 `setBackgroundDrawable()` 方法更改窗口背景。完整代码如下: ```java @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.myButton) { // 更换 app 背景 Drawable newBackground = getResources().getDrawable(R.drawable.new_background); getWindow().setBackgroundDrawable(newBackground); return true; } return super.onOptionsItemSelected(item); } ``` 其中,`new_background` 是您要更换的新背景图片的资源 ID。在此方法中,我们使用 `getResources().getDrawable()` 方法获取资源文件,并将其设置为窗口背景。这样,当用户点击菜单项时,窗口背景就会更换为新的背景图片。 完成这些步骤后,您的按钮就可以添加更换 app 背景的功能了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值