java - Android:如何将两个按钮添加到操作栏中

标签 java android button android-actionbar about-box

我想在操作栏中添加两个按钮,但在我的例子中只出现一个按钮。我的代码有什么问题?

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

<item android:id="@+id/action_about"
    android:title="@string/action_about"
    android:icon="@drawable/ic_action_about"
    myApp:showAsAction="ifRoom"/> 
</menu>

最佳答案

像这样使用 always 而不是 ifRoom

<menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:myapp="http://schemas.android.com/apk/res-auto" >
<item android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:icon="@drawable/ic_action_settings"
      myapp:showAsAction="always"/>

<item android:id="@+id/action_about"
    android:title="@string/action_about"
    android:icon="@drawable/ic_action_about"
    myapp:showAsAction="always"/> 
</menu>

阅读文档

You can also use "always" to declare that an item always appear as an action button. However, you should not force an item to appear in the action bar this way. Doing so can create layout problems on devices with a narrow screen. It's best to instead use "ifRoom" to request that an item appear in the action bar, but allow the system to move it into the overflow when there's not enough room. However, it might be necessary to use this value if the item includes an action view that cannot be collapsed and must always be visible to provide access to a critical feature.

Reference

关于java - Android:如何将两个按钮添加到操作栏中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21868389/

相关文章:

java - 在 Java 中禁用退格键

java - 如何在 Spring 中使用 @ConfigurationProperties 加载名称值属性

android - Android GC 日志消息的含义

android - 使用模糊 View 作为相对 View

android - 如何与私有(private)测试版用户一起发布

c - 让这个计数器更好地工作

javascript - 另外,在使用 setLoggedIn 时最好使用回调选项,以便捕获之前版本的状态,如下所示 :

java - 无法使用java更新mysql中的列值?

java - 为什么对于 POST 请求,Retrofit2 使用 @Field 而不是 @Body

html - 从 html 按钮溢出的文本似乎与应用的样式形成对比