Android Snackbar布局

时间:2016-12-25 00:38:58

标签: android android-snackbar

如何在Google云端硬盘上自定义我的Snackbar布局,如下所示?

Google drive Snackbar

编辑:这是唯一的方法吗? how to customize snackBar's layout?

2 个答案:

答案 0 :(得分:0)

为什么这需要// this method gets called by Spring after the GET/POST request but before the // binding of request parameters... // for POST requests, we want the enity @ModelAttribute("formName") // <---- Note the attribute name...this is important public Object getFormBackingObject(HttpServletRequest request) { if(!request.getMethod().equals("POST")) { return null; } // find primary key String id = request.getParameter("id"); return serviceObject.getMyEntity(id); } @RequestMapping(value="/edit/{id}", method=RequestMethod.POST) public String editProcessPost(@PathVariable Integer id, @ModelAttribute("formName") BPostForm editPost) { // editPost is the fully populated entity from the DB after request params // have been bound to it. myService.save(editPost); return "whatever...."; } ?只需在布局底部添加一个视图,其中包含您需要的信息。

StackLayout

答案 1 :(得分: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