0%
常见属性:
- View.SYSTEM_UI_FLAG_FULLSCREEN:全屏
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE:显示状态栏
- View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:隐藏导航栏
常见实现方式:
1 2
| mActivity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_FULLSCREEN);
|
1 2 3 4 5
| mActivity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_FULLSCREEN |View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
mActivity.getWindow().setStatusBarColor(Color.TRANSPARENT);
|
1 2 3
| mActivity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_FULLSCREEN |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
1 2 3 4 5 6 7 8
| mActivity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_STABLE |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_FULLSCREEN |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
沉浸式状态栏的实现:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
public class SystemUI extends AppCompatActivity { public static void fixSystemUI(Activity mActivity){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ mActivity.getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_LAYOUT_STABLE); mActivity.getWindow().setStatusBarColor(Color.TRANSPARENT); } } }
|
1 2 3 4 5 6 7 8 9
| public class BaseUIActivity extends AppCompatActivity {
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState);
SystemUI.fixSystemUI(this); } }
|
隐藏 ActionBar:
AndroidManifest.xml1 2 3 4 5 6 7 8 9 10 11 12
| <application ...> <activity android:name=".MainActivity" // 添加主题 android:theme="@style/Theme.AppCompat.Light.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
|