Created
September 11, 2019 04:13
-
-
Save claireliu14/ebddf1818ea618ac4529c10eb5214e1f to your computer and use it in GitHub Desktop.
Make App bar and status bar transparent without FLAG_LAYOUT_NO_LIMITS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
REFERENCE