1.问题如下,安卓布局很不协调
2.先将ActionBar设置为NoActionBar
先打开styles.xml
3.使用工具类
/*** StatusBar 工具类*/
public class StatusBarUtil {/*** 设置状态栏全透明** @param activity 需要设置的activity*/public static void setTransparent(Activity activity) {transparentStatusBar(activity);setRootView(activity);}/*** 使状态栏透明*/private static void transparentStatusBar(Activity activity) {activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//需要设置这个flag contentView才能延伸到状态栏activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);//状态栏覆盖在contentView上面,设置透明使contentView的背景透出来activity.getWindow().setStatusBarColor(Color.TRANSPARENT);}/*** 设置根布局参数*/private static void setRootView(Activity activity) {ViewGroup parent = activity.findViewById(android.R.id.content);for (int i = 0, count = parent.getChildCount(); i < count; i++) {View childView = parent.getChildAt(i);if (childView instanceof ViewGroup) {childView.setFitsSystemWindows(true);((ViewGroup) childView).setClipToPadding(true);}}}
}
4.问题解决