2016-12-25 70 views

回答

0

我設法解決了Mike和JJD anwser here。這裏是我的代碼

在我的活動:

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> 

最終結果 final result

0

爲什麼這需要是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>