我有显示搜索栏的活动。我没有使用appbarlayout,因为我的最新版本的Android Studio出现了渲染问题。当我单击搜索按钮时,位于框架布局中的recyclerview消失了。按下搜索按钮时,我需要装卸吗?
activity_rating.xml
<layout 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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.view.RatingActivity">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="10dp"
android:fitsSystemWindows="true"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/lblAdvancedSearch"
style="@style/AppTheme.AppCompatTextView_1"
android:backgroundTint="@color/md_grey_500"
android:drawablePadding="16dp"
android:hint="@string/lbl_AdvancedSearch"
android:textAlignment="textEnd"
app:drawableEndCompat="@drawable/ic_search_black_24dp" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/AdvancedSearchForm"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
tools:visibility="visible">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/TextInputLayout_TerminalID"
style="@style/AppTheme.TextInputLayout_1"
android:hint="@string/lbl_TerminalID"
app:counterEnabled="true"
app:counterMaxLength="@integer/terminal_id_input_length"
app:errorEnabled="true"
app:hintAnimationEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/TextInputEditText_TerminalID"
style="@style/AppTheme.EditTextLayout_1"
/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/TextInputLayout_BranchCode"
style="@style/AppTheme.TextInputLayout_1"
android:hint="Branch Code"
app:counterEnabled="true"
app:counterMaxLength="@integer/terminal_id_input_length"
app:errorEnabled="true"
app:hintAnimationEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/TextInputEditText_BranchCode"
style="@style/AppTheme.EditTextLayout_1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/TextInputLayout_DepartmentCode"
style="@style/AppTheme.TextInputLayout_1"
android:hint="@string/lbl_DepartmentCode"
app:counterEnabled="true"
app:counterMaxLength="@integer/terminal_id_input_length"
app:errorEnabled="true"
app:hintAnimationEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/TextInputEditText_DepartmentCode"
style="@style/AppTheme.EditTextLayout_1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/TextInputLayout_StaffID"
style="@style/AppTheme.TextInputLayout_1"
android:hint="@string/lbl_StaffID"
app:counterEnabled="true"
app:counterMaxLength="@integer/terminal_id_input_length"
app:errorEnabled="true"
app:hintAnimationEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/TextInputEditText_StaffID"
style="@style/AppTheme.EditTextLayout_1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/MaterialButton_Search"
style="@style/AppTheme.MaterialButton_1"
android:layout_gravity="center"
android:background="@color/md_purple_700"
android:drawableStart="@drawable/ic_search_black_24dp"
android:drawableTint="@color/md_white_1000"
android:text="@string/lbl_btnSearch"
android:textAlignment="center"
android:textColor="@color/md_white_1000" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
<FrameLayout
android:id="@+id/fragmentsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
RatingActivity.java
package com.action_and_notification.ui.view;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import com.action_and_notification.R;
import com.action_and_notification.databinding.ActivityRatingBinding;
public class RatingActivity extends AppCompatActivity {
ActivityRatingBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating);
binding = DataBindingUtil.setContentView(this, R.layout.activity_rating);
binding.lblAdvancedSearch.setOnClickListener(v -> {
if (binding.AdvancedSearchForm.getVisibility() == View.GONE) {
binding.AdvancedSearchForm.setVisibility(View.VISIBLE);
} else if (binding.AdvancedSearchForm.getVisibility() == View.VISIBLE) {
binding.AdvancedSearchForm.setVisibility(View.GONE);
}
});
if (findViewById(R.id.fragmentsContainer) != null) {
if (savedInstanceState != null) {
return;
}
RatingList_Fragment ratingList_fragment = new RatingList_Fragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentsContainer, ratingList_fragment).commit();
}
}
}