解決android 顯示內(nèi)容被底部導(dǎo)航欄遮擋的問題
描述:
由于產(chǎn)品需求,要求含有EditText的界面全屏顯示,最好的解決方式是使用AndroidBug5497Workaround.assistActivity(this)
的方式來(lái)解決,但是華為和魅族手機(jī)系統(tǒng)自帶的有底部導(dǎo)航欄,會(huì)造成一些布局被遮擋。
解決方案:在values-21的style.xml中添加android:windowDrawsSystemBarBackgrounds”并將值設(shè)置為false,方式如下
在style引用的主題里面加入android:windowDrawsSystemBarBackgrounds”并將值設(shè)置為false,會(huì)自動(dòng)提醒點(diǎn)擊alt+Enter會(huì)新建values-21的文件夾并生成styles.xml的文件。
也可以自己忽略的,直接新建values-21的文件夾然后新建一個(gè)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();
//這個(gè)判斷是為了解決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);
//這個(gè)判斷是為了解決19之后的版本在彈出軟鍵盤時(shí),鍵盤和推上去的布局(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)航欄遮擋的問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Android 中使用RadioGroup和Fragment實(shí)現(xiàn)底部導(dǎo)航欄的功能
- 性能分析:指如何快速定位SQL問題
- android中Fragment+RadioButton實(shí)現(xiàn)底部導(dǎo)航欄
- Android自定義ViewPagerIndicator實(shí)現(xiàn)炫酷導(dǎo)航欄指示器(ViewPager+Fragment)
- Android程序開發(fā)之Fragment實(shí)現(xiàn)底部導(dǎo)航欄實(shí)例代碼
- Android實(shí)現(xiàn)沉浸式通知欄通知欄背景顏色跟隨app導(dǎo)航欄背景顏色而改變
- Android實(shí)現(xiàn)底部導(dǎo)航欄功能(選項(xiàng)卡)
- 超簡(jiǎn)單的幾行代碼搞定Android底部導(dǎo)航欄功能
- Android 彈出Dialog時(shí)隱藏狀態(tài)欄和底部導(dǎo)航欄的方法
- Android 沉浸式狀態(tài)欄與隱藏導(dǎo)航欄實(shí)例詳解
- android 全屏去掉底部虛擬導(dǎo)航欄的方法
- Android仿今日頭條頂部導(dǎo)航欄效果的實(shí)例代碼
- Android仿網(wǎng)易客戶端頂部導(dǎo)航欄效果
- Android?Fragment實(shí)現(xiàn)頂部、底部導(dǎo)航欄
相關(guān)文章
Android TreeView實(shí)現(xiàn)帶復(fù)選框樹形組織結(jié)構(gòu)
這篇文章主要為大家詳細(xì)介紹了Android TreeView實(shí)現(xiàn)帶復(fù)選框樹形組織結(jié)構(gòu),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
Android下拉刷新框架實(shí)現(xiàn)代碼實(shí)例
這篇文章主要介紹了Android下拉刷新框架實(shí)現(xiàn)代碼實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2016-11-11
使用PHP開發(fā)Android應(yīng)用程序技術(shù)介紹
這篇文章主要介紹了使用PHP開發(fā)Android應(yīng)用程序技術(shù)介紹,本文講解了安裝PHP for Android、設(shè)置PHP for Android開發(fā)環(huán)境、使用PHP構(gòu)建Android應(yīng)用程序,需要的朋友可以參考下2015-03-03
Android 中ActionBar+fragment實(shí)現(xiàn)頁(yè)面導(dǎo)航的實(shí)例
這篇文章主要介紹了Android 中ActionBar+fragment實(shí)現(xiàn)頁(yè)面導(dǎo)航的實(shí)例的相關(guān)資料,希望通過本文能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-09-09
詳解Android的自動(dòng)化構(gòu)建及發(fā)布
本篇文章主要介紹了Android的自動(dòng)化構(gòu)建及發(fā)布,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-06-06
Android源碼系列之深入理解ImageView的ScaleType屬性
Android源碼系列第一篇,這篇文章主要從源碼的角度深入理解ImageView的ScaleType屬性,感興趣的小伙伴們可以參考一下2016-06-06
Android使用CoordinatorLayout實(shí)現(xiàn)底部彈出菜單
這篇文章主要為大家詳細(xì)介紹了Android使用CoordinatorLayout實(shí)現(xiàn)底部彈出菜單,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-11-11
Android 調(diào)用設(shè)備已有的相機(jī)應(yīng)用詳情
這篇文章主要介紹了Android 調(diào)用設(shè)備已有的相機(jī)應(yīng)用,如果我們只是需要讓用戶能夠拍攝照片,則可以直接請(qǐng)求已有相機(jī)應(yīng)用拍攝照片并將照片返回給我們,下面我們一起來(lái)看看這些功能,需要的朋友可以參考一下2021-10-10

