简体   繁体   English

Android Snackbar布局

[英]Android Snackbar layout

How can i customize my Snackbar layout like on Google Drive as shown below? 如何在Google云端硬盘上自定义我的Snackbar布局,如下所示?

谷歌驱动器Snackbar

EDIT: Is this the only way around? 编辑:这是唯一的方法吗? how to customize snackBar's layout? 如何自定义snackBar的布局?

Why would this need to be a snackbar ? 为什么这需要成为snackbar吧? Just add a view at the bottom of the layout that holds the information you need. 只需在布局底部添加一个视图,其中包含您需要的信息。

 <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>

I've managed to work it out with Mike and JJD anwser here . 我已经设法在这里与Mike和JJD anwser合作。 Here's my code 这是我的代码

At my 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();
}

My layout: 我的布局:

<?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>

Final result 最后结果 最后结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM