解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問題
描述:
由于產(chǎn)品需求,要求含有EditText的界面全屏顯示,最好的解決方式是使用AndroidBug5497Workaround.assistActivity(this)
的方式來解決,但是華為和魅族手機(jī)系統(tǒng)自帶的有底部導(dǎo)航欄,會造成一些布局被遮擋。
解決方案:在values-21的style.xml中添加android:windowDrawsSystemBarBackgrounds”并將值設(shè)置為false,方式如下
在style引用的主題里面加入android:windowDrawsSystemBarBackgrounds”并將值設(shè)置為false,會自動提醒點(diǎn)擊alt+Enter會新建values-21的文件夾并生成styles.xml的文件。
也可以自己忽略的,直接新建values-21的文件夾然后新建一個styles.xml的文件,將主題里面的內(nèi)容復(fù)制到styles.xml里面然后加上加入android:windowDrawsSystemBarBackgrounds”并將值設(shè)置為false即可解決。
例外:附上(網(wǎng)上找到的)
public class AndroidBug5497Workaround { // For more information, see https://code.google.com/p/android/issues/detail?id=5497 // To use this class, simply invoke assistActivity() on an Activity that already has its content view set. public static void assistActivity (Activity activity) { new AndroidBug5497Workaround(activity); } private Activity activity; private View mChildOfContent; private int usableHeightPrevious; private FrameLayout.LayoutParams frameLayoutParams; private AndroidBug5497Workaround(Activity activity) { this.activity = activity; FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content); mChildOfContent = content.getChildAt(0); mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout() { possiblyResizeChildOfContent(); } }); frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams(); } private void possiblyResizeChildOfContent() { int usableHeightNow = computeUsableHeight(); LogUtils.e("possiblyResizeChildOfContent","usableHeightNow:"+usableHeightNow); LogUtils.e("possiblyResizeChildOfContent","usableHeightPrevious:"+usableHeightPrevious); if (usableHeightNow != usableHeightPrevious) { int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight(); //這個判斷是為了解決19之前的版本不支持沉浸式狀態(tài)欄導(dǎo)致布局顯示不完全的問題 if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){ Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; usableHeightSansKeyboard -= statusBarHeight; } int heightDifference = usableHeightSansKeyboard - usableHeightNow; if (heightDifference > (usableHeightSansKeyboard/4)) { // keyboard probably just became visible frameLayoutParams.height = usableHeightSansKeyboard - heightDifference; } else { // keyboard probably just became hidden frameLayoutParams.height = usableHeightSansKeyboard; } mChildOfContent.requestLayout(); usableHeightPrevious = usableHeightNow; } } private int computeUsableHeight() { Rect frame = new Rect(); activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; Rect r = new Rect(); mChildOfContent.getWindowVisibleDisplayFrame(r); //這個判斷是為了解決19之后的版本在彈出軟鍵盤時,鍵盤和推上去的布局(adjustResize)之間有黑色區(qū)域 的問題 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ return (r.bottom - r.top)+statusBarHeight; } return (r.bottom - r.top); } }
以上這篇解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
- Android 中使用RadioGroup和Fragment實現(xiàn)底部導(dǎo)航欄的功能
- 性能分析:指如何快速定位SQL問題
- android中Fragment+RadioButton實現(xiàn)底部導(dǎo)航欄
- Android自定義ViewPagerIndicator實現(xiàn)炫酷導(dǎo)航欄指示器(ViewPager+Fragment)
- Android程序開發(fā)之Fragment實現(xiàn)底部導(dǎo)航欄實例代碼
- Android實現(xiàn)沉浸式通知欄通知欄背景顏色跟隨app導(dǎo)航欄背景顏色而改變
- Android實現(xiàn)底部導(dǎo)航欄功能(選項卡)
- 超簡單的幾行代碼搞定Android底部導(dǎo)航欄功能
- Android 彈出Dialog時隱藏狀態(tài)欄和底部導(dǎo)航欄的方法
- Android 沉浸式狀態(tài)欄與隱藏導(dǎo)航欄實例詳解
- android 全屏去掉底部虛擬導(dǎo)航欄的方法
- Android仿今日頭條頂部導(dǎo)航欄效果的實例代碼
- Android仿網(wǎng)易客戶端頂部導(dǎo)航欄效果
- Android?Fragment實現(xiàn)頂部、底部導(dǎo)航欄
相關(guān)文章
Android 中NumberPicker,DatePicker與DatePickerDialog中分割顏色的修改實例代
這篇文章主要介紹了Android 中NumberPicker,DatePicker與DatePickerDialog中分割顏色的修改實例代碼的相關(guān)資料,這里提供實例代碼,需要的朋友可以參考下2017-03-03Android使用viewpager實現(xiàn)自動無限輪播圖
這篇文章主要介紹了Android使用viewpager實現(xiàn)自動無限輪播圖效果,實現(xiàn)方法大概有兩種,一種是viewpager+作為游標(biāo)的點(diǎn) 。另外一種是重寫viewpager,具體實現(xiàn)過程大家參考下本文2018-06-06Android編譯出現(xiàn)Warning:Mapping?new?ns?to?old?ns報錯的解決方案
android在編譯的過程中難免會出現(xiàn)些錯誤,下面這篇文章主要給大家介紹了關(guān)于Android編譯出現(xiàn)Warning:Mapping?new?ns?to?old?ns報錯的解決方案,需要的朋友可以參考下2023-02-02Android修行手冊之ConstraintLayout布局使用詳解
這篇文章主要為大家介紹了Android修行手冊之ConstraintLayout使用示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Android 使用Vitamio打造自己的萬能播放器(4)——本地播放(快捷搜索、數(shù)據(jù)存儲)
本文主要介紹android Vitamio 本地播放功能(快捷搜索,數(shù)據(jù)存儲),這里提供實例代碼和效果圖,有需要的小伙伴可以參考下2016-07-07Android RecyclerView添加上拉加載更多功能
這篇文章主要為大家詳細(xì)介紹了Android RecyclerView如何添加上拉加載更多功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-10-10Android中利用C++處理Bitmap對象的實現(xiàn)方法
下面小編就為大家?guī)硪黄狝ndroid中利用C++處理Bitmap對象的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03android開發(fā)教程之開機(jī)啟動服務(wù)service示例
如果開機(jī)啟動一個Activity,開機(jī)首先看的界面,是你的程序界面,如果為了,開機(jī)后也啟動你的程序,但是不顯示自己程序的界面,就要用Service服務(wù),下面是開機(jī)啟動服務(wù)service示例2014-03-03