Skip to content

Instantly share code, notes, and snippets.

@claireliu14
Last active June 27, 2019 07:59
Show Gist options
  • Save claireliu14/0062f4beaef16bcd7b29c4ddefd70b1b to your computer and use it in GitHub Desktop.
Save claireliu14/0062f4beaef16bcd7b29c4ddefd70b1b to your computer and use it in GitHub Desktop.
Make App bar and Status bar transparent.
<!-- activity_main.xml (root) -->
+ android:fitsSystemWindows="true"
<!-- app_bar_main.xml -->
<com.google.android.material.appbar.AppBarLayout
android:paddingTop="24dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting status bar
Window window = this.getWindow();
window.setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
setContentView(R.layout.activity_main);
// ...
}
<!-- styles.xml -->
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="android:windowTranslucentStatus">true</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
<!-- v21\styles.xml -->
<resources>
<style name="AppTheme.NoActionBar">
...
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment