logo
down
shadow

How to create android snackbar with custom layout


How to create android snackbar with custom layout

By : Csaba Sári
Date : November 29 2020, 09:01 AM
Any of those help Custom layouts are discouraged due to the intended use of Snackbars, they're essentially "interactive toasts" and shouldn't contain anything more than a message and an action.See the design guidelines for more information.
code :


Share : facebook icon twitter icon
Android: detecting snackbar dismiss or timeout in coordinator layout's behaviour

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

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

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

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

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>
Related Posts Related Posts :
  • Save and Retrieve location inside JPEG image
  • Intent share is not able to attach image
  • Search specific nearby places using google places api web services for android
  • How to update app?
  • Is It possible to develop app with react native and make changes in android studio?
  • How to create Motion Splash Screen in Android?
  • Build Gradle Android studio Build Slow
  • Using Android DownloadManager,how do i get file name?
  • Android - How to Load More then 20mb Image in Imageview
  • Notification is not cancelled after calling notification.cancel
  • How to implement the smart-crop feature
  • Null Pointer exception on reading SMS stored in SIM in Android
  • remove google text from google maps in android
  • Image captured from camera not displaying in imageview android
  • kivy: My screenmanager code is not working with scrollview
  • Dynamic MpAndroidChart Not Working
  • Yandex Maps return 403 Forbidden using retrofit
  • how set selected spinner item in android studio?
  • Does Picasso library for Android handle image loading while network connectivity is off?
  • colorAccent in Holo Theme
  • Android: animation on layout after button clicked for minimum SDK version of 14
  • Are static variable truly "global" (system-wide) in Android?
  • Animate a car(Marker) along a path in google map android
  • Default to "compass" (gyroscope) mode when viewing a photosphere
  • Gradle - finished with non-zero exit value 1
  • Android Studio 2.0 Application crash on unmodified Application class
  • Android Studio cursor display error
  • Creating Dagger 2 component to be shared between src/test and src/androidTest
  • Android losing state when screen is OFF and ON again
  • Android Notification.Builder addAction PendingIntent Fragment
  • Use another button instead of back button
  • Android Studio Send string over socket after taking a picture [Google Glass]
  • Realm `access from incorrect thread` error when using shared code between IntentService and AsyncTask (Android)
  • osmdroid plotting current location offline
  • GifAnimationDrawable(Gif file) not playing in ListView
  • Controlling emission of Observable items in unit tests
  • android: Log in Button
  • Gradle github and facebook dependencies can't resolve
  • How can you animate a view back and forth between two states on Android, while supporting backpressure?
  • $(LOCAL_PATH) not returning the path to current directory correctly
  • Error:Cause: com.android.sdklib.repository.FullRevision
  • How to get an offset in RecyclerView ItemDecorator
  • Android toolbar home button not showing
  • TextView keeps popping up
  • Toolbar overlaps below status bar
  • Inflated view not updating
  • Errors of the Manifest
  • How to perform the same operation on several elements in array in doInBackground()
  • see error when use getSupportActionBar().setDisplayHomeAsUpEnabled(true)
  • What the heck is going on with this animation?
  • How to set the color of the counter on a TextInputLayout?
  • Cannot resolve symbol 'GeoJsonLayer '
  • Font file not loading on Libgdx Android
  • Simulate GCM push notifications on Android
  • Google maps provider, Wifi, 3g and GPS
  • Textview animation error
  • I want my FAB to stay at the bottom of the screen
  • How to attach multiple Images with a note taking app in android?
  • How to share xml layout using Intent.ACTION_SEND
  • Is there a default selector for the RecyclerView
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co