1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cn.flightfeather.thirdapp.common;
 
import android.os.Build;
import android.support.v4.app.Fragment;
import android.view.ViewGroup;
 
/**
 * Created by note_ff_1603 on 2017/7/28.
 */
 
public class StatusBar {
    private Fragment fragment;
 
    public StatusBar(Fragment fragment) {
        this.fragment = fragment;
    }
    public StatusBar(android.app.Fragment fragment) {
    }
 
    public StatusBar(){
    }
 
    //初始化半透明状态栏
    public void initTransparentStatsBar(ViewGroup viewGroup) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            viewGroup.setPadding(0, getStatusBarHeight(), 0, 0);
        }
    }
 
    //获得状态栏高度
    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = fragment.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = fragment.getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
}