Skip to content

Commit 7b09483

Browse files
smdyvthestinger
smdyv
authored andcommitted
Add margins to toolbar
1 parent 1fbfc86 commit 7b09483

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

app/src/main/java/org/grapheneos/pdfviewer/PdfViewer.java

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.view.MenuInflater;
1414
import android.view.MenuItem;
1515
import android.view.View;
16+
import android.view.ViewGroup;
1617
import android.webkit.CookieManager;
1718
import android.webkit.JavascriptInterface;
1819
import android.webkit.WebResourceRequest;
@@ -25,6 +26,9 @@
2526

2627
import androidx.annotation.NonNull;
2728
import androidx.appcompat.app.AppCompatActivity;
29+
import androidx.core.graphics.Insets;
30+
import androidx.core.view.ViewCompat;
31+
import androidx.core.view.WindowInsetsCompat;
2832
import androidx.loader.app.LoaderManager;
2933
import androidx.loader.content.Loader;
3034

@@ -153,6 +157,17 @@ protected void onCreate(Bundle savedInstanceState) {
153157
setContentView(binding.getRoot());
154158
setSupportActionBar(binding.toolbar);
155159

160+
// Margins for the toolbar are needed, so that content of the toolbar
161+
// is not covered by a system button navigation bar when in landscape.
162+
ViewCompat.setOnApplyWindowInsetsListener(binding.toolbar, (v, windowInsets) -> {
163+
Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
164+
ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
165+
mlp.leftMargin = insets.left;
166+
mlp.rightMargin = insets.right;
167+
v.setLayoutParams(mlp);
168+
return windowInsets;
169+
});
170+
156171
binding.webview.setBackgroundColor(Color.TRANSPARENT);
157172

158173
if (BuildConfig.DEBUG) {

0 commit comments

Comments
 (0)