Last active
February 8, 2020 06:39
-
-
Save yunusemredilber/558b7080e6235d9df33856465c920aad to your computer and use it in GitHub Desktop.
Webview In Navigation View (Drawer) [ Android ]
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
public class SomeActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.webview_in_drawer_layout); | |
// ... | |
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout); | |
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( | |
this, drawerLayout, null, R.string.app_name, R.string.app_name); | |
drawerLayout.addDrawerListener(toggle); | |
toggle.syncState(); | |
// To make webview full screen | |
View view = findViewById(R.id.some_full_screen_view); | |
ViewTreeObserver viewTreeObserver = view.getViewTreeObserver(); | |
if (viewTreeObserver.isAlive()) { | |
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { | |
@Override | |
public void onGlobalLayout() { | |
view.getViewTreeObserver().removeOnGlobalLayoutListener(this); | |
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) navigationView.getHeaderView(0).findViewById(R.id.webview).getLayoutParams(); | |
params.height = view.getHeight()-50; | |
navigationView.getHeaderView(0).findViewById(R.id.webview).setLayoutParams(params); | |
} | |
}); | |
} | |
} | |
} |
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:layout_width="match_parent" | |
android:id="@+id/drawer_layout" | |
android:layout_height="match_parent"> | |
<androidx.coordinatorlayout.widget.CoordinatorLayout android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<!-- Your content --> | |
</androidx.coordinatorlayout.widget.CoordinatorLayout> | |
<com.google.android.material.navigation.NavigationView | |
android:id="@+id/navigation" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:fitsSystemWindows="true" | |
android:backgroundTint="#fff" | |
android:layout_gravity="start|left" | |
android:nestedScrollingEnabled="true" | |
app:headerLayout="@layout/navigationview_header"/> | |
</androidx.drawerlayout.widget.DrawerLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment