本文介绍了如何定制小吃店的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一个小吃店的布局改变自定义视图的方法?

Is there any method to change the layout of a snackBar to custom View?

现在谈到黑,我们可以改变背景颜色。
但我不知道充气一个新的布局,使之作为背景小吃店正确的方式?

Now it comes black and we can change the background color.But I don't know the right way to inflate a new layout and making it as snackBars background?

谢谢...

推荐答案

的小吃吧不允许您设置自定义布局。然而,随着Primoz990建议你可以得到小吃吧的看法。该getView函数返回Snackbar.SnackbarLayout,这是一个水平的LinearLayout对象,其子女是一个TextView和一个按钮。为了自己的视图添加到小吃吧,你只需要隐藏TextView的,和你的视图添加到Snackbar.SnackbarLayout。

The Snackbar does not allow you to set a custom layout. However, as Primoz990 suggested you can get the Snackbar's View. The getView function returns the Snackbar.SnackbarLayout, which is a horizontal LinearLayout object whose children are a TextView and a Button. To add your own View to the Snackbar, you just need to hide the TextView, and add your View to the Snackbar.SnackbarLayout.

// Create the Snackbar
Snackbar snackbar = Snackbar.make(containerLayout, "", Snackbar.LENGTH_LONG);
// Get the Snackbar's layout view
Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) snackbar.getView();
// Hide the text
TextView textView = (TextView) layout.findViewById(android.support.design.R.id.snackbar_text);
textView.setVisibility(View.INVISIBLE);

// Inflate our custom view
View snackView = mInflater.inflate(R.layout.my_snackbar, null);
// Configure the view
ImageView imageView = (ImageView) snackView.findViewById(R.id.image);
imageView.setImageBitmap(image);
TextView textViewTop = (TextView) snackView.findViewById(R.id.text);
textViewTop.setText(text);
textViewTop.setTextColor(Color.WHITE);

// Add the view to the Snackbar's layout
layout.addView(snackView, 0);
// Show the Snackbar
snackbar.show();

这篇关于如何定制小吃店的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 20:57