热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在导航栏中将后退按钮更改为向下箭头-Changebackbuttontoarrow-downinNavigationBar

ImusinganAppCompatDialogFragmenttoshowaBottomSheetDialog.ClickingthebackbuttonontheNa

I'm using an AppCompatDialogFragment to show a BottomSheetDialog. Clicking the back button on the Navigation Bar closes the BottomSheetDialog.

我正在使用AppCompatDialogFragment来显示BottomSheetDialog。单击导航栏上的后退按钮将关闭BottomSheetDialog。

I want to change the icon on the Navigation Bar from the back button to the 'arrow-down' icon. This is by default done when the keyboard is shown and I want to replicate it for the Bottom Sheet.

我想将导航栏上的图标从后退按钮更改为“向下箭头”图标。默认情况下,这是在显示键盘时完成的,我想为底部工作表复制它。

To be clear, here what I have:

要清楚,我在这里:

Current

And here is what I need:

这就是我需要的:

This is what I want

Note that the back button is an "arrow-down".

请注意,后退按钮是“向下箭头”。

The navigation-bar is a system-ui component and I don't see the way to change it's appearance to look like the navigation-bar displayed when the keyboard is visible.

导航栏是一个系统ui组件,我没有看到改变它的外观的方式,看起来像键盘可见时显示的导航栏。

3 个解决方案

#1


8  

In android O the concept of changing the icon is introduced but it is still through the 3rd party app. Custom Navigation Bar that uses WRITE_SECURE_SETTINGS to change the icons. In Android O you can change the display of the bar i.e Light or Dark theme.

在Android O中,引入了更改图标的概念,但它仍然通过第三方应用程序。自定义导航栏使用WRITE_SECURE_SETTINGS来更改图标。在Android O中,您可以更改条形图的显示,即浅色或深色主题。

Solution 2 can be more of a help to you. You can create a popup window on navigation Bar with the desired layout i.e 3 buttons back, Recent Apps and home button. In this way you can change the back button icon accordingly. Make sure the pop up window is of same height as the navigation Bar and you can then make your own functions for home and recent apps and in back function you can close your BottomSheetDialog and remove that popup window.

解决方案2可以为您提供更多帮助。您可以在导航栏上创建一个弹出窗口,其中包含所需的布局,即3个按钮,最近的应用程序和主页按钮。通过这种方式,您可以相应地更改后退按钮图标。确保弹出窗口与导航栏的高度相同,然后您可以为家庭和最近的应用程序创建自己的功能,在后退功能中,您可以关闭BottomSheetDialog并删除该弹出窗口。

The below is the code for home key as well as recent Apps. For back button do accordingly what you want to achieve with your own icon.

以下是主页密钥以及最近的应用程序的代码。对于后退按钮,请使用您自己的图标执行相应的操作。

For Home Button.

对于主页按钮。

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

For Recent Apps.

对于最近的应用。

Class serviceManagerClass = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClass.getMethod("getService", String.class);
IBinder retbinder = (IBinder) getService.invoke(serviceManagerClass, "statusbar");
Class statusBarClass = Class.forName(retbinder.getInterfaceDescriptor());
Object statusBarObject = statusBarClass.getClasses()[0].getMethod("asInterface", IBinder.class).invoke(null, new Object[] { retbinder });
Method clearAll = statusBarClass.getMethod("toggleRecentApps");
clearAll.setAccessible(true);
clearAll.invoke(statusBarObject);

For Back Button // use your icon and function of closing the BottomSheetDialog.

对于后退按钮//使用关闭BottomSheetDialog的图标和功能。

For calculating the height of the navigationBar

用于计算navigationBar的高度

public static int getSoftButtonsBarSizePort(Activity activity) {
    // getRealMetrics is only available with API 17 and +
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        DisplayMetrics metrics = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int usableHeight = metrics.heightPixels;
        activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
        int realHeight = metrics.heightPixels;
        if (realHeight > usableHeight)
            return realHeight - usableHeight;
        else
            return 0;
    }
    return 0;
}

you can also do it by adb commands but make sure it can mess up your navigationBar and you cannot get back your original navigationBar.

您也可以通过adb命令执行此操作,但请确保它可能会弄乱您的navigationBar并且您无法取回原始的navigationBar。

I hope it helps.

我希望它有所帮助。

#2


4  

As already answered, it will be introduced in Android O.

正如已经回答的那样,它将在Android O中引入。

For prior versions it's only possible for Android 3.x, or 4.4+ using flags as SYSTEM_UI_FLAG_IMMERSIVE, SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, SYSTEM_UI_FLAG_HIDE_NAVIGATION, etc. But still very limited, putting a lot of effort you get a result not very friendly or even glitchy.

对于以前的版本,它只能用于Android 3.x,或4.4+使用标志作为SYSTEM_UI_FLAG_IMMERSIVE,SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN,SYSTEM_UI_FLAG_HIDE_NAVIGATION等。但仍然非常有限,付出了很多努力,你得到的结果不是很友好甚至是小故障。

The reason because it isn't possible, it because is a security issue. Apps could prevent to users to exit of the app.

原因是因为它不可能,因为它是一个安全问题。应用可能会阻止用户退出应用。

Look at these links :

看看这些链接:

  • Android overlay on top of software buttons
  • Android覆盖在软件按钮之上

  • Hide System Bar in Tablets
  • 在平板电脑中隐藏系统栏

  • http://room-15.github.io/blog/2015/03/17/overlaying-the-system-navigation-bar/

#3


0  

This article describes very well how it can be done in Android Oreo.

本文非常好地介绍了如何在Android Oreo中完成。


推荐阅读
author-avatar
mobiledu2502921033
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有