Android: detecting snackbar dismiss or timeout in coordinator layout's behaviour
By : karabo matsemela
Date : March 29 2020, 07:55 AM
it should still fix some issue The default behaviour of FloatingActionButton is reacting to your case. Try looking into android.support.design.widget.FloatingActionButton.Behavior and see, why FloatingActionButton is reacting to the Snackbar. From quickly looking into the source code, you should override:
|
Android Snackbar does not take full width when trying to inflate custom layout
By : X Star
Date : March 29 2020, 07:55 AM
Does that help I am trying to change the snackbar with my custom layout but custom layout does not take full width of snackbar.Why? , Please add below line in your code:- code :
layout.setPadding(0, 0, 0, 0); //set padding to 0
|
How to pop up whole fragment layout with Android snackbar
By : bogale bethania
Date : March 29 2020, 07:55 AM
it should still fix some issue I'd don't have any floating buttons but I'd like to pop up whole layout when a snackbar msg is shown. For that I am wrapping my fragment into a CoordinatorLayout like so: , Write your own behavior, that reacts to showing Snackbar: code :
public class FrameLayoutBehavior extends CoordinatorLayout.Behavior<FrameLayout> {
private float mFrTranslationY;
public FrameLayoutBehavior (Context context, AttributeSet attrs) {
super();
}
@Override
public boolean layoutDependsOn(final CoordinatorLayout parent, final FrameLayout child, final View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(final CoordinatorLayout parent, final FrameLayout child, final View dependency) {
if (dependency instanceof Snackbar.SnackbarLayout) {
updateFabTranslationForSnackbar(parent, child, dependency);
ViewCompat.setTranslationY(child, mFrTranslationY);
}
return false;
}
@Override
public void onDependentViewRemoved(final CoordinatorLayout parent, final FrameLayout child, final View dependency) {
super.onDependentViewRemoved(parent, child, dependency);
}
private void updateFabTranslationForSnackbar(CoordinatorLayout parent, final FrameLayout fab, View snackbar) {
mFrTranslationY = getFabTranslationYForSnackbar(parent, fab, snackbar);
}
private float getFabTranslationYForSnackbar(CoordinatorLayout parent, FrameLayout fab, View snackbar) {
float minOffset = 0;
minOffset = Math.min(minOffset, ViewCompat.getTranslationY(snackbar) - snackbar.getHeight());
return minOffset;
}
}
@CoordinatorLayout.DefaultBehavior(FrameLayoutBehavior.Behavior.class)
|
Android Snackbar layout
By : JakeV.
Date : March 29 2020, 07:55 AM
will be helpful for those in need I've managed to work it out with Mike and JJD anwser here. Here's my code At my activity: code :
private void showLoggedUser() {
View view = findViewById(android.R.id.content);
Snackbar snackbar = Snackbar.make(view, "", Snackbar.LENGTH_LONG);
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
layout.findViewById(android.support.design.R.id.snackbar_text).setVisibility(View.INVISIBLE);
FirebaseUser currentUser = FirebaseUtils.getCurrentUser();
View snackView = mInflater.inflate(R.layout.login_snackbar, null);
((TextView)snackView.findViewById(R.id.user_name)).setText(currentUser.getDisplayName());
((TextView)snackView.findViewById(R.id.user_mail)).setText(currentUser.getEmail());
final ImageView imageview = (ImageView) snackView.findViewById(R.id.user_ic);
ImageDownloader imageDownloader = new ImageDownloader() {
@Override
protected void onPostExecute(Bitmap bitmap) {
RoundedBitmapDrawable bmDrawable;
bmDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
bmDrawable.setCornerRadius(Math.max(bitmap.getWidth(), bitmap.getHeight()) / 2.0f);
imageview.setImageDrawable(bmDrawable);
}
};
imageDownloader.execute(currentUser.getPhotoUrl().toString());
layout.addView(snackView, 0);
snackbar.show();
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent" android:gravity="center_vertical"
android:paddingTop="@dimen/activity_margin" android:paddingBottom="@dimen/activity_margin">
<ImageView
android:id="@+id/user_ic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_user_white"
android:adjustViewBounds="false" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="10dp">
<TextView
android:text="Username"
android:id="@+id/user_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.SearchResult.Subtitle"
android:textColor="@android:color/white" />
<TextView
android:text="Usermail"
android:id="@+id/user_mail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:textColor="@android:color/white" />
</LinearLayout>
|
Android - Snackbar not visible in fragment/coordinator layout
By : user2935088
Date : March 29 2020, 07:55 AM
I wish this helpful for you I incrementally made changes, adding margins to the recycler view (they should probably be present regardless), it had no effect. The only change that had any effect was ensuring that the root view was the Coordinator Layout. code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/task_coordinator_layout"
tools:context="com.pomodorocentral.task.dashboard.TaskFragment"
android:theme="@style/MyTheme.DayNight.NoActionBar"
android:background="?android:windowBackground"
android:layout_marginTop="50dp"
android:layout_marginBottom="50dp">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ToolBarStyle"
app:popupTheme="@style/ToolBarStyle.Popup"
android:id="@+id/task_toolbar"
android:elevation="4dp"
app:subtitle="Show Tasks">
<com.google.android.material.chip.ChipGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/task_status_filter_group"
android:visibility="visible"
app:chipSpacing="4dp"
android:layout_margin="16dp">
<com.google.android.material.chip.Chip
style="@style/CustomChip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/active_status_label"
android:id="@+id/active_status_chip"
app:checkedIconEnabled="true"
app:checkedIcon="@drawable/ic_check_white_24dp"
app:chipEndPadding="10dp"
app:chipStartPadding="10dp"
android:includeFontPadding="false"
android:elegantTextHeight="false"/>
<com.google.android.material.chip.Chip
style="@style/CustomChip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/completed_status_label"
android:id="@+id/completed_status_chip"
app:checkedIconEnabled="true"
app:checkedIcon="@drawable/ic_check_white_24dp"
/>
</com.google.android.material.chip.ChipGroup>
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/task_empty_view"
android:paddingTop="70dp"
android:paddingBottom="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/addTaskButton"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
app:layout_constraintHorizontal_bias="0.0"
android:theme="@style/MyTheme.DayNight"
android:visibility="invisible"
android:layout_marginTop="50dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="30dp"
tools:layout_editor_absoluteX="121dp"
android:id="@+id/task_empty_heading"
tools:text="@string/task_empty_heading"
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
android:gravity="center"
android:visibility="visible"
android:text="@string/task_empty_heading"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/task_empty_text"
android:textAppearance="@style/TextAppearance.MaterialComponents.Caption"
tools:text="@string/task_empty_text"
android:visibility="visible"
android:text="@string/task_empty_text"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:gravity="center_vertical|center"/>
<ImageView
app:srcCompat="@drawable/ic_pomodoro_shrug"
android:layout_width="match_parent"
android:layout_height="340dp"
android:id="@+id/task_empty_image"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:cropToPadding="true"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginBottom="?attr/actionBarSize"
android:id="@+id/task_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
app:srcCompat="@drawable/ic_add_black_24dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:id="@+id/addTaskButton"
android:layout_gravity="end|bottom"
android:focusable="true"
android:layout_margin="16dp"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|