gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:10:13 28 4
gpt4 key购买 nike

我正在使用 AppCompatDialogFragment 来显示 BottomSheetDialog。单击 Navigation Bar 上的后退按钮会关闭 BottomSheetDialog

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

要清楚,这里有什么:

Current

这就是我需要的:

This is what I want

请注意,返回按钮是“向下箭头”。

导航栏是一个系统用户界面组件,我看不到如何将其外观更改为键盘可见时显示的导航栏。

最佳答案

在 android O 中引入了更改图标的概念,但仍然是通过 3rd 方应用程序。 Custom Navigation Bar使用 WRITE_SECURE_SETTINGS 来更改图标。在 Android O 中,您可以更改栏的显示,即 Light 或 Dark 主题。

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

以下是 Home 键以及最近的应用程序的代码。对于后退按钮,请使用您自己的图标相应地执行您想要实现的操作。

对于主页按钮。

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

对于最近的应用程序。

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);

返回按钮//使用你的图标和关闭BottomSheetDialog的功能。

用于计算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;
}

你也可以通过 adb 命令来做到这一点,但要确保它会弄乱你的 navigationBar 并且你无法找回原来的 navigationBar

希望对你有帮助。

关于android - 在导航栏中将后退按钮更改为向下箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45721170/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com