【发布时间】:2019-06-16 17:04:16
【问题描述】:
我想通过手机上的主页按钮创建一个活动。 在某些设备中,主页按钮覆盖活动。 我该如何解决这个问题?
谢谢
【问题讨论】:
标签: android android-homebutton
我想通过手机上的主页按钮创建一个活动。 在某些设备中,主页按钮覆盖活动。 我该如何解决这个问题?
谢谢
【问题讨论】:
标签: android android-homebutton
如果您指的是导航栏并基于this 问题,则解决方案是将这些属性添加到 value-21 style.xml 中:
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:fitsSystemWindows">true</item>
另一种方法是:
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;
}
【讨论】: