简体   繁体   English

如何在旧的Android API上执行操作栏设置图标

[英]How to enforce action bar settings icon at old android APIs

The new android smartphones have no menu settings button. 新的android智能手机没有菜单设置按钮。 Instead, the settings icon is in the ActionBar. 而是,设置图标位于ActionBar中。

If I run my app on an old smartphone, there is no settings icon in the actionbar. 如果我在旧的智能手机上运行应用程序,则操作栏中将没有设置图标。 You have to click at the menu settings button of the smartphone. 您必须单击智能手机的菜单设置按钮。

How can I enforce at older smartphones (APIs) that the settings icon is also in the ActionBar? 如何在较旧的智能手机(API)上强制设置图标也在ActionBar中?

What you describe is actually intended by design as per the Backwards compatibility section of the Android Design Guide. 根据Android设计指南的向后兼容性部分 ,您所描述的内容实际上设计目的

Android phones with traditional navigation hardware keys don't display the virtual navigation bar at the bottom of the screen. 具有传统导航硬件键的Android手机不会在屏幕底部显示虚拟导航栏。 Instead, the action overflow is available from the menu hardware key 相反,可以从菜单硬件键获得操作溢出

A quote from a previous answer explains why you shouldn't be concerned with this behaviour: 上一个答案的引言解释了为什么您不应该担心这种行为:

Ultimately it's more important to the user experience that your app behave consistently with every other app on the same device, than that it behave consistently with itself across all devices. 最终,对于用户体验而言,您的应用程序与同一设备上的所有其他应用程序保持一致 ,比在所有设备上与自身保持一致的行为更为重要。 - (source) - (来源)

However, if you are still adamant you wish to see the same UI across all devices you can consider the following: 但是,如果您仍然坚持要在所有设备上看到相同的UI,则可以考虑以下几点:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/menu_overflow"
        android:icon="@drawable/overflow_image"
        android:orderInCategory="11111"
        android:showAsAction="always">
        <menu>
            <item
                android:id="@+id/settings_item"
                android:showAsAction="never"
                android:title="@string/settings"/>
        </menu>
    </item>  
</menu>

This example would use a drawable resource overflow_image , as the 'three dots' and always show on the toolbar and behave as you require. 本示例将使用一个可绘制的资源overflow_image作为“三个点”,并始终显示在工具栏上并按照您的要求运行。 You would just need to source the correct drawable 您只需要提供正确的可绘制对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM