QMUI_Android狀態(tài)欄相關(guān)

最近用了一下QMUI_Android這個整體的ui框架,詳細(xì)的不多說有很多的解釋,今天想聊一下狀態(tài)欄的問題。
如果你繼承了QMUIActivity這個activity的話,那么你的狀態(tài)欄就會跟著背景顏色一樣。因為有個需求狀態(tài)欄的顏色要藍色的,但是整個界面的背景是白色的,一開始想的是自己處理一下就可以了。結(jié)果多出來一塊跟狀態(tài)欄一樣高的白色的橫條就像下邊這樣


白條.png

因為我們了解setFitsSystemWindows這個方法是設(shè)置不是直接到狀態(tài)欄的 我們貼一下這個方法

 /**
     * Sets whether or not this view should account for system screen decorations
     * such as the status bar and inset its content; that is, controlling whether
     * the default implementation of {@link #fitSystemWindows(Rect)} will be
     * executed.  See that method for more details.
     *
     * <p>Note that if you are providing your own implementation of
     * {@link #fitSystemWindows(Rect)}, then there is no need to set this
     * flag to true -- your implementation will be overriding the default
     * implementation that checks this flag.
     *
     * @param fitSystemWindows If true, then the default implementation of
     * {@link #fitSystemWindows(Rect)} will be executed.
     *
     * @attr ref android.R.styleable#View_fitsSystemWindows
     * @see #getFitsSystemWindows()
     * @see #fitSystemWindows(Rect)
     * @see #setSystemUiVisibility(int)
     */
    public void setFitsSystemWindows(boolean fitSystemWindows) {
        setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS);
    }

所以我在Activity設(shè)置false但是運行的還是有一條。fragment設(shè)置也是這樣。百思不得其解。
直到我看了一下QMUIActivity他的源碼,找到了原因


    @Override
    public void setContentView(int layoutResID) {
        SwipeBackLayout swipeBackLayout = SwipeBackLayout.wrap(this,
                layoutResID, dragBackEdge(), mSwipeCallback);
//就是這個地方,
        if (translucentFull()) {
            swipeBackLayout.getContentView().setFitsSystemWindows(false);
        } else {
            swipeBackLayout.getContentView().setFitsSystemWindows(true);
        }
        mListenerRemover = swipeBackLayout.addSwipeListener(mSwipeListener);
        super.setContentView(swipeBackLayout);
    }

接下來我們看一下translucentFull()這個方法


    /**
     * Immersive processing
     *
     * @return if true, the area under status bar belongs to content; otherwise it belongs to padding
     */
    protected boolean translucentFull() {
        return false;
    }

所以這個方法是控制是不是狀態(tài)欄跟背景一個顏色的方法。所以我再MainActivity重寫一下這個方法,返回true
那么這個頂部那個白天就沒了。下邊看一下效果。

沒有白條.png

所以整理一下。提醒一下大家遇到這個問題的時候可以不遇到這個坑。
更多精彩請關(guān)注公眾號及時接收

公眾號
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容