【问题标题】:Android, How to display Snackbar without visible view?Android,如何在没有可见视图的情况下显示 Snackbar?
【发布时间】:2016-04-24 06:47:42
【问题描述】:

我试图显示在 snakbar 中收到的任何短信,即使用户不在我的应用程序之外,是否可以显示它?

这是我之前使用 Toast 的代码:

    public class SmsReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        final Bundle bundle = intent.getExtras();
        try {
            if (bundle != null) {
                final Object[] pdusObj = (Object[]) bundle.get("pdus");
                for (int i = 0; i < pdusObj.length; i++) {
                    SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdusObj[i]);

                    String message = sms.getDisplayMessageBody();

                    Toast toast= Toast.makeText(context ,message, Toast.LENGTH_SHORT);
                    toast.setGravity(Gravity.TOP, 0, 150);
                    toast.show();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

【问题讨论】:

  • 在android中如果你想给用户信息或消息你可以使用通知。顺便说一句,当您尝试提供有关新消息的使用信息时,小吃店并不是最好的方法
  • @Gujarat Santana 实际上,我不需要显示整个消息正文,只会显示模式为 4-6 位的数字。它适用于 Toast,但我很难控制 toast 的持续时间

标签: android android-snackbar


【解决方案1】:

参考http://developer.android.com/reference/android/support/design/widget/Snackbar.html

Snackbar will try and find a parent view to hold Snackbar's view from the value given to view.

在这种情况下,您应该使用 Toast 或 Notification!

【讨论】:

    猜你喜欢
    • 2019-12-07
    • 2012-01-22
    • 2017-04-10
    • 2020-10-01
    • 2013-03-31
    • 1970-01-01
    • 2015-01-04
    • 2012-06-05
    • 2016-04-19
    相关资源
    最近更新 更多