我想在操作栏中添加两个按钮,但在我的例子中只出现一个按钮。我的代码有什么问题?
<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.
关于java - Android:如何将两个按钮添加到操作栏中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21868389/