Я знаю, что по умолчанию только плавающая кнопка меняет свое положение, когда появляется дикая Снэк-бар.
Но если мы посмотрим на этот вопрос (очень близкий к моему), мы сможем найти решение здесь .
Исходя из этого, я надеюсь, что у нас есть похожее или лучшее решение для Layout Coordinator.
Что происходит:
Моя кнопка сохранения закрылась при появлении снэк-бара.
(извините, размер изображения в стеке с s.png не работает)
Что я хочу:
Моя кнопка или весь режим ограничений появляются при появлении Snackbar
Мой код:
xml код
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/background_white_round">
<TextView
android:id="@+id/dialog_title_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:text="@string/str_title"
android:textColor="@color/solito_text_black"
android:textSize="@dimen/size_text_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/dialog_description_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="20dp"
android:text="@string/str_loading"
android:textColor="@color/solito_text_grey_dark"
android:textSize="@dimen/size_text_normal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/dialog_title_text" />
<Button
android:id="@+id/dialog_ok_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="24dp"
android:background="@color/background_transparent"
android:text="@android:string/ok"
android:textColor="@color/solito_button_purple"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/dialog_description_text"/>
<Button
android:id="@+id/dialog_cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="24dp"
android:background="@color/background_transparent"
android:text="@string/str_cancel"
android:textColor="@color/solito_button_purple"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/dialog_ok_btn"
app:layout_constraintTop_toBottomOf="@id/dialog_description_text"/>
</android.support.constraint.ConstraintLayout>
код Java
private void showSnackBarUndo() {
//Snack Bar to Undo
Snackbar snackbar = Snackbar
.make(Objects.requireNonNull(getView()), getResources().getString(R.string.str_list_cleaned), Snackbar.LENGTH_LONG)
.setAction(getResources().getString(R.string.str_undo), new View.OnClickListener() {
@Override
public void onClick(View view) {
DataStorePersistence.getInstance().setAddressArrayListTemp(getContext(), listTitle, listID, addressArrayListUndo);
updateListContent();
Snackbar
.make(getView(),
getResources().getString(R.string.str_list_restored),
Snackbar.LENGTH_SHORT)
.show();
}
});
snackbar.show();
}
EDIT :
Я перепробовал много вещей. Пример попытаться поставить поведение в одной кнопке класса, но не сработало. Изучая Material Design Android не выглядит так, как будто вы хотите, чтобы вы поместили свою кнопку внизу экрана. Так что сейчас я перехожу на плавающую кнопку Это не решение вопроса, но, возможно, помочь кому-то, кто попадает сюда.