gpt4 book ai didi

android - 如何在屏幕顶部显示 Snackbar

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:18:07 25 4
gpt4 key购买 nike

正如 Android 文档所说

Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom of the screen on mobile and lower left on larger devices.

有没有其他方法可以让我们在屏幕顶部而不是底部显示 snackbars

现在我正在做这样的事情,在屏幕底部显示一个 snackbar

Snackbar.make(findViewById(android.R.id.content), "Hello this is a snackbar!!!", 
Snackbar.LENGTH_LONG).setAction("Undo", mOnClickListener)
.setActionTextColor(Color.RED)
.show();

最佳答案

使用这个可以让 snackbar 出现在屏幕顶部:

Snackbar snack = Snackbar.make(parentLayout, str, Snackbar.LENGTH_LONG);
View view = snack.getView();
FrameLayout.LayoutParams params =(FrameLayout.LayoutParams)view.getLayoutParams();
params.gravity = Gravity.TOP;
view.setLayoutParams(params);
snack.show();

来自 OP:

I had to change the first line:

Snackbar snack = Snackbar.make(findViewById(android.R.id.content), "Had a snack at Snackbar", Snackbar.LENGTH_LONG);

关于android - 如何在屏幕顶部显示 Snackbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31746300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com