Android 小吃栏布局

Android Snackbar layout

我如何自定义我的 Snackbar 布局,就像在 Google 驱动器上一样,如下所示?

编辑:这是唯一的解决办法吗?

为什么需要 snackbar?只需在布局底部添加一个包含您需要的信息的视图。

 <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:background="@android:color/black"
    android:layout_alignParentStart="true">

    <ImageView
        android:id="@+id/image"
        android:src="@drawable/image"
        android:layout_width="50dp"
        android:layout_height="50dp"/>

    <TextView
        android:id="@+id/email"
        android:textSize="25sp"
        android:textColor="@android:color/white"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Email"
        android:layout_alignParentBottom="true"
        android:layout_toEndOf="@+id/image" />

    <TextView
        android:id="@+id/name"
        android:textSize="25sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@android:color/white"
        android:text="Name"
        android:layout_alignParentTop="true"
        android:layout_toEndOf="@+id/image" />
</RelativeLayout>

我已经设法与 Mike 和 JJD anwser 一起解决了这个问题。这是我的代码

在我的 activity:

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>

最终结果