第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何以編程方式獲取Android導(dǎo)航欄的高度和寬度?

如何以編程方式獲取Android導(dǎo)航欄的高度和寬度?

回首憶惘然 2019-10-15 16:01:31
屏幕底部的黑色導(dǎo)航欄無法在Android中輕松移除。從3.0開始,它已成為Android的一部分,以替代硬件按鈕。這是一張圖片:如何獲得此UI元素的寬度和高度的大?。ㄒ韵袼貫閱挝唬??
查看完整描述

4 回答

?
墨色風(fēng)雨

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個贊

試試下面的代碼:


Resources resources = context.getResources();

int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");

if (resourceId > 0) {

    return resources.getDimensionPixelSize(resourceId);

}

return 0;


查看完整回答
反對 回復(fù) 2019-10-15
?
泛舟湖上清波郎朗

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超3個贊

NavigationBar的高度對于某些設(shè)備有所不同,但對于某些方向也有所不同。首先,你必須檢查設(shè)備是否有一個導(dǎo)航欄,那么如果該設(shè)備是平板電腦或不片劑(手機(jī)),最后你得看設(shè)備的方向,以獲得正確的高度。


public int getNavBarHeight(Context c) {

         int result = 0;

         boolean hasMenuKey = ViewConfiguration.get(c).hasPermanentMenuKey();

         boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);


         if(!hasMenuKey && !hasBackKey) {

             //The device has a navigation bar

             Resources resources = c.getResources();


             int orientation = resources.getConfiguration().orientation;

             int resourceId;

             if (isTablet(c)){

                 resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape", "dimen", "android");

             }  else {

                 resourceId = resources.getIdentifier(orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_width", "dimen", "android");     

             }


             if (resourceId > 0) {

                 return resources.getDimensionPixelSize(resourceId);

             }

         }

         return result;



private boolean isTablet(Context c) {

    return (c.getResources().getConfiguration().screenLayout

            & Configuration.SCREENLAYOUT_SIZE_MASK)

            >= Configuration.SCREENLAYOUT_SIZE_LARGE;

}


查看完整回答
反對 回復(fù) 2019-10-15
?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個贊

實(shí)際上,平板電腦(至少是Nexus 7)上的導(dǎo)航欄在縱向和橫向上都有不同的尺寸,因此此功能應(yīng)如下所示:


private int getNavigationBarHeight(Context context, int orientation) {

    Resources resources = context.getResources();


    int id = resources.getIdentifier(

            orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape",

            "dimen", "android");

    if (id > 0) {

        return resources.getDimensionPixelSize(id);

    }

    return 0;

}


查看完整回答
反對 回復(fù) 2019-10-15
  • 4 回答
  • 0 關(guān)注
  • 1008 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號