gpt4 book ai didi

java - 搜索后导航栏不在最后位置

转载 作者:行者123 更新时间:2023-11-29 18:26:44 25 4
gpt4 key购买 nike

我已经实现了一个 SearchBar,在我得到结果后,我想通过使用模拟器的“X”图标或“后退”键退出导航栏,但导航栏没有转到最后一个位置我该如何解决?

应用程序问题的屏幕截图 -> https://imgur.com/gallery/V2JN7HA

一些我用来清除状态的代码

public void getText(最终 View View ) {

    final SearchView sv = view.findViewById(R.id.searchView);
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if(query.length() >= 1){
userInput = query;
fetchData();

setAdapter(view);
sv.clearFocus();

view.requestFocus();
return true;
}
setUpView(view);
observeDataChange();
setAdapter(view);

sv.clearFocus();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if(newText.length() >= 1){
userInput = newText;
fetchData();

setAdapter(view);
//sv.clearFocus();

view.requestFocus();
return true;
}
return false;
}

});

}

最佳答案

用下面的代码替换你的activity_main.xml文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp">


<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />


</androidx.constraintlayout.widget.ConstraintLayout>

和 fragment_dashboard.xml 由

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_height="match_parent"
android:background="@color/cardview_shadow_end_color"
tools:context=".MainActivity">

<TextView
android:id="@+id/text_dashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="8dp"
android:textAlignment="center"
android:textSize="0sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_of_photos"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginEnd="4dp"
android:layout_marginRight="2dp"
android:background="@color/cardview_shadow_end_color"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.516"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.666" />

</androidx.constraintlayout.widget.ConstraintLayout>

关于java - 搜索后导航栏不在最后位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58491578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com