您的位置:首页 > 移动开发 > Android开发

android开发:mx2隐藏虚拟菜单

2014-03-10 13:04 316 查看
//获取actionbar高度

private static int getActionBarHeight(Context context) {

  int result = 0;

  TypedArray actionbarSizeTypedArray = context

    .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });

  result = (int) actionbarSizeTypedArray.getDimension(0, 0);

  return result;

 }

//获取statusbar高度

 private static int getStatusBarHeight(Context context) {

  int result = 0;

  int resourceId = context.getResources().getIdentifier(

  "status_bar_height", "dimen", "android");

  if (resourceId > 0) {

   result = context.getResources().getDimensionPixelSize(resourceId);

  }

  return result;

 }

public static boolean hasSmartBar() {

  try {

   Method method = Class.forName("android.os.Build").getMethod(

   "hasSmartBar");

   return ((Boolean) method.invoke(null)).booleanValue();

  } catch (Exception e) {

  }

  if (Build.DEVICE.equals("mx2")) {

   return true;

  } else if (Build.DEVICE.equals("mx") || Build.DEVICE.equals("m9")) {

   return false;

  }

  return false;

 }

 

 public static void hide(Context context, Window window,

   int statusBarHeight, int smartBarHeight) {

  if (!hasSmartBar()) {

   return;

  }

  if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {

   return;

  }

  window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

  WindowManager.LayoutParams.FLAG_FULLSCREEN);

  window.addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

  window.getDecorView()

  .setPadding(0, statusBarHeight, 0, -smartBarHeight);

 }

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息