显示在操作栏中的三个点的菜单项,而无需使用&QUOT最佳途径;黑客"方法栏中、菜单项、黑客、途径

2023-09-12 23:40:06 作者:念念不忘念念伤

我有点困惑。我想说明三个点项目内部的操作栏的剩余项目。但我总是失去它时,项目的数量增加了! Google上搜寻了一​​点后,我发现这个有用的方法:ASMUIRTI答

I am a little confused. I want to show the remaining items of the action bar inside the three dot item. But i always lose it when the number of items increases ! after googling a little, i found this "useful" method : ASMUIRTI ANSWER

private void getOverflowMenu() {
    try {
       ViewConfiguration config = ViewConfiguration.get(this);
       Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
       if(menuKeyField != null) {
           menuKeyField.setAccessible(true);
           menuKeyField.setBoolean(config, false);
       }
   } catch (Exception e) {
       e.printStackTrace();
   }
 }

我测试了它,这工作,因为我想要的。不幸的是,triing更好地理解请问这个方法做的,我发现它的 的可怕的黑客工具,打破一致性的应用程序的平台上休息 (adamp的评论)

I tested it and that work as i want. Unfortunately, triing to better understand what does this method do, i found that it's an awful hack that breaks consistency with the rest of the apps on the platform (adamp's comment)

有谁能告诉我,为什么这是一个黑客,什么是最好的解决办法?

Can somebody tell me why it's a hack, and what is the best solution ?

推荐答案

这很简单。有些设备的菜单按钮,有的则没有。在与菜单按钮的设备四溢的行动项目时显示pressing菜单按钮和设备,而无需他们在pressing的三个点显示。这就是设备制造商设计了他们的设备和任何企图迫使他们不同的方法来做这被认为是一个黑客。这是不一致,因为在同一设备上的其他应用程序做到这一点是不同的。

It's simple. Some devices have menu buttons others don't. On devices with menu buttons the overflowing action items are shown when pressing the menu button and on devices without they are shown when pressing the three dots. That's how the device manufacturer designed their devices and any attempt to force them to do it differently is regarded a "hack". It's inconsistent because other apps on the same device do it differently.

这一切都归结到问题,你是否想为在不同的设备或稠度一个单一的应用程序用于在单个设备上所有应用程序的一致性。由于应用程序开发应该是关于用户进行到底,IMO单个设备(一个用户)上的一致性是真正重要的。

It all comes down to the question whether you want to have consistency for a single app across different devices or consistency for all apps on a single device. Because app development should be about users in the end, IMO the consistency on a single device (for one user) is what really counts.

要对付它的最好方法就是使用android:showAsAction标签,让Android的决定,如何显示在动作条的行动,是否需要与否溢出菜单,如果是用户如何访问四溢行动项目。

The best way to deal with this is to use the android:showAsAction tags and let Android decide, how to display the actions in the ActionBar, whether an overflow menu is needed or not and if yes how the user accesses the overflowing action items.