Skip to content

Instantly share code, notes, and snippets.

@claireliu14
Created September 11, 2019 04:13
Show Gist options
  • Save claireliu14/ebddf1818ea618ac4529c10eb5214e1f to your computer and use it in GitHub Desktop.
Save claireliu14/ebddf1818ea618ac4529c10eb5214e1f to your computer and use it in GitHub Desktop.
Make App bar and status bar transparent without FLAG_LAYOUT_NO_LIMITS
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:context=".MainActivity"
tools:openDrawer="start"
tools:showIn="@layout/activity_main">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="225dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
android:fitsSystemWindows="true"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_home"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/content_main"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:elevation="0dp"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginTop="24dp"
android:background="@android:color/transparent"
android:elevation="0dp"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting status bar
final Window window = this.getWindow();
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
// prepare view
setContentView(R.layout.activity_main);
// Toolbar
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// drawer toggle
final DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.setFitsSystemWindows(true);
drawer.setClipToPadding(false);
// ...
}
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<!--<item name="android:windowTranslucentStatus">false</item>-->
<!--<item name="android:windowLightStatusBar">false</item>-->
</style>
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<!--<item name="android:windowDrawsSystemBarBackgrounds">false</item>-->
<!--<item name="android:windowTranslucentStatus">true</item>-->
</style>
</resources>
@claireliu14
Copy link
Author

REFERENCE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment