无法操作按钮添加到Android的工作室我的行动吧 [英] Unable to add action buttons to my action bar in android studio

查看:101
本文介绍了无法操作按钮添加到Android的工作室我的行动吧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在密切关注网站上的步骤

https://developer.android.com/training/basics/动作条/加-buttons.html ,并在这个阶段,要我复制并粘贴code以添加一个动作搜索并操作设置教程。然而,当我跑我的应用程序,动作搜索不希望出现。

我也取得了一定要包括动作搜索图标的.png,但仍不会显示。

我也试图改变我的build.gradle的minimumsdk版本8至11的网站的建议,但也不能工作。但是,如果我没有记错的话,操作栏是在应用程序中,虽然present因为溢出是存在的。

从我的胡乱猜测,它可能是在code是过时的,因为我已经注意到了很多事情已经改变,因为撰写本教程。但我仍然毫无头绪这个奇怪的问题。


解决方案

 <菜单的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
 的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto><项目
    机器人:ID =@ + ID / action_settings
    机器人:orderInCategory =1
    应用:showAsAction =总是
    机器人:图标=@绘制/ ic_action_settings
    机器人:标题=@字符串/ action_settings/>
<项目
    机器人:ID =@ + ID /卷
    机器人:orderInCategory =2
    机器人:标题=批量
    机器人:图标=@绘制/ ic_action_volume_on
    应用:showAsAction =总是/>

您需要的xmlns引用RES-汽车,然后用它作为我在code已经使用。希望这有助于。

I am currently closely following the steps on the website

https://developer.android.com/training/basics/actionbar/adding-buttons.html and at this stage of the tutorial it wants me to copy and paste the code to add an action search and action settings. However, when I run my application, the action search doesn't want to appear.

I have also made sure to include a .png for the icon of the action search, but still won't show.

I have also tried changing the minimumsdk version in my build.gradle from 8 to 11 as suggested by the website, but didn't work either. However, if I am not mistaken, the action bar is present in the app though since the overflow is there.

From my wild guess, it might be that the code is outdated since I have noticed a lot of things have changed since this tutorial was written. But I am still clueless about this weird problem.

解决方案

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

<item
    android:id="@+id/action_settings"
    android:orderInCategory="1"
    app:showAsAction="always"
    android:icon="@drawable/ic_action_settings"
    android:title="@string/action_settings"/>
<item
    android:id="@+id/volume"
    android:orderInCategory="2"
    android:title="Volume"
    android:icon="@drawable/ic_action_volume_on"
    app:showAsAction="always"/>

You need to xmlns referencing res-auto and then use it as I have used in my code. Hope this helps.

这篇关于无法操作按钮添加到Android的工作室我的行动吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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