最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android如何解決虛擬按鍵欄遮擋問題

 更新時間:2021年03月25日 10:34:59   作者:龍旋  
這篇文章主要介紹了Android如何解決虛擬按鍵欄遮擋問題,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下

最近在公司的項目中 , 華為用戶反饋出了一個問題 , 華為手機底部有虛擬按鍵欄把應(yīng)用的底部內(nèi)容遮擋住了 , 現(xiàn)在已經(jīng)把這個問題解決了 , 記錄一下,給各位遇到相同問題的童鞋做一下參考.

這里的解決方案還是相對比較簡單的,首先判斷用戶的手機是否存在虛擬按鍵,若存在,那么就獲取虛擬按鍵的高度,然后再用代碼設(shè)置相同高度的TextView,這樣手機的虛擬按鍵就不會將底部的內(nèi)容遮擋住了。

處理虛擬按鍵欄工具類:

public class ScreenUtils {
  //獲取虛擬按鍵的高度
  public static int getNavigationBarHeight(Context context) {
    int result = 0;
    if (hasNavBar(context)) {
      Resources res = context.getResources();
      int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
      if (resourceId > 0) {
        result = res.getDimensionPixelSize(resourceId);
      }
    }
    return result;
  }

  /**
   * 檢查是否存在虛擬按鍵欄
   *
   * @param context
   * @return
   */
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  public static boolean hasNavBar(Context context) {
    Resources res = context.getResources();//讀取系統(tǒng)資源函數(shù)
    int resourceId = res.getIdentifier("config_showNavigationBar", "bool", "android");//獲取資源id
    if (resourceId != 0) {
      boolean hasNav = res.getBoolean(resourceId);
      // check override flag
      String sNavBarOverride = getNavBarOverride();
      if ("1".equals(sNavBarOverride)) {
        hasNav = false;
      } else if ("0".equals(sNavBarOverride)) {
        hasNav = true;
      }
      return hasNav;
    } else { // fallback
      return !ViewConfiguration.get(context).hasPermanentMenuKey();
    }
  }

  /**
   * 判斷虛擬按鍵欄是否重寫
   * @return
   */
  private static String getNavBarOverride() {
    String sNavBarOverride = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      try {
        Class c = Class.forName("android.os.SystemProperties");
        Method m = c.getDeclaredMethod("get", String.class);
        m.setAccessible(true);
        sNavBarOverride = (String) m.invoke(null, "qemu.hw.mainkeys");
      } catch (Throwable e) {
      }
    }
    return sNavBarOverride;
  }
}

調(diào)用工具類方法 , 獲取虛擬按鍵高度:

//處理虛擬按鍵
//判斷用戶手機機型是否有虛擬按鍵欄       
 if(ScreenUtils.hasNavBar(getApplicationContext())){
  setNavigationBar();
  }

 //處理虛擬按鍵
 private void setNavigationBar() {
  int barHeight = ScreenUtils.getNavigationBarHeight(getApplicationContext());
  LinearLayout.LayoutParams barParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);
  TextView tv = new TextView(this);
  tv.setHeight(barHeight);
  tv.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
  tv.setBackgroundColor(Color.BLACK);
  llNavigationBar.addView(tv,barParams);
 }

到這里就結(jié)束啦!

以上就是Android如何解決虛擬按鍵欄遮擋問題的詳細內(nèi)容,更多關(guān)于Android 虛擬按鍵欄遮擋的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

麟游县| 淳安县| 吉安县| 杭州市| 康马县| 保定市| 阿克陶县| 新田县| 永登县| 永州市| 江北区| 尚义县| 麻阳| 河曲县| 长治市| 宜兰县| 太谷县| 青海省| 宣武区| 米脂县| 柳江县| 东阳市| 延长县| 高陵县| 保山市| 冷水江市| 尤溪县| 疏附县| 保康县| 阿拉善左旗| 东兰县| 磴口县| 贵港市| 定兴县| 丹阳市| 沙洋县| 安康市| 邯郸市| 内黄县| 葵青区| 临颍县|