嗨,经过大约一周的工作,我找到了完美的解决方案。
主要活动
protected void onCreate(Bundle savedInstanceState)
{
etWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
((LinearLayout.LayoutParams)
mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
}
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
AndroidManifest 活动添加此行
<activity
android:name=".activity.Main"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustPan"
android:fitsSystemWindows="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
风格V21
<style name="myTheme" parent="FridayfairTheme.Base">
<item name="android:windowTranslucentNavigation">true</item>
</style>