Skip to content

Commit

Permalink
为搜索页面添加基于导航栏高度的垫高
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsummer233 committed Mar 14, 2024
1 parent d43d304 commit a3b19af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ private void initSearchView() {

mSearchView.setOnClickListener(v -> startSearchMode());
mSearchAdapter.setOnItemClickListener((view, ad) -> onSearchItemClickListener(ad));

ViewCompat.setOnApplyWindowInsetsListener(mSearchResultView, new OnApplyWindowInsetsListener() {
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
Insets inset = Insets.max(insets.getInsets(WindowInsetsCompat.Type.systemBars()),
insets.getInsets(WindowInsetsCompat.Type.displayCutout()));
v.setPadding(0, 0, 0, inset.bottom);
return insets;
}
});
}

private void initNavigationView() {
Expand Down Expand Up @@ -160,11 +171,6 @@ private void addPaddingForRadioButton(View view, Context context) {
@NonNull
@Override
public WindowInsetsCompat onApplyWindowInsets(@NonNull View v, @NonNull WindowInsetsCompat insets) {
/*WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
int dpi = displayMetrics.densityDpi;*/
Insets inset = Insets.max(insets.getInsets(WindowInsetsCompat.Type.systemBars()),
insets.getInsets(WindowInsetsCompat.Type.displayCutout()));
v.setPadding(0, dpToPx(10, context), 0, inset.bottom + dpToPx(18, context));
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
android:layout_height="match_parent"
android:layout_marginTop="@dimen/miuix_appcompat_searchbar_result_margin_top"
android:background="?android:attr/windowBackground"
android:clipToPadding="false"
android:visibility="gone" />

</FrameLayout>

0 comments on commit a3b19af

Please sign in to comment.