//判斷是否有虛擬鍵盤
@SuppressLint("NewApi")
public static boolean checkDeviceHasNavigationBar(Context activity) {
//通過判斷設備是否有返回鍵、菜單鍵(不是虛擬鍵,是手機屏幕外的按鍵)來確定是否有navigation bar
boolean hasMenuKey = ViewConfiguration.get(activity)
.hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap
.deviceHasKey(KeyEvent.KEYCODE_BACK);
if (!hasMenuKey && !hasBackKey) {
// 做任何你需要做的,這個設備有一個導航欄
return true;
}
return false;
}
//獲取虛擬鍵盤高度
public static int getNavigationBarHeight(Context activity) {
Resources resources = activity.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height",
"dimen", "android");
//獲取NavigationBar的高度
int height = resources.getDimensionPixelSize(resourceId);
return height;
}
虛擬返回鍵菜單鍵是否存在及其高度獲取
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.