【问题标题】:Align Snackbar's Action on the right对齐 Snackbar 的 Action 在右侧
【发布时间】:2016-10-28 13:18:32
【问题描述】:

下午好,

我正在使用 Snackbars 并尝试放置一个 aciton(如 UNDO),但文本未与屏幕右侧对齐。

我需要的结果:

我得到的结果:

如您所见,“UNDO”操作未按我的需要对齐。

这是我的 Snackbar 代码:

Snackbar snackbar = Snackbar.make(mMainContent, "Message deleted", Snackbar.LENGTH_LONG)
                        .setAction("UNDO", new View.OnClickListener() {
                            @Override
                            //Todo: Click on "UNDO"
                            public void onClick(View view) {
                            }
                        });

                snackbar.setActionTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white));

                View snackbarView = snackbar.getView();
                snackbarView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent));
                snackbar.show();

有人可以帮助我吗?

谢谢!

【问题讨论】:

  • 你必须更喜欢这个默认值,因为Documentation没有方法。

标签: android android-snackbar snackbar


【解决方案1】:

创建您自己的自定义小吃店布局Custom snackbar

核心部分如下

<!-- language: lang-java -->

// 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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-06
    • 2017-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多