【问题标题】:How to make the start Snackbar message when you click on the menu?单击菜单时如何制作启动 Snackbar 消息?
【发布时间】:2016-01-01 04:34:06
【问题描述】:

点击菜单时如何制作启动Snackbar消息?

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case (R.id.reset):
            number1.setText(null);
            number2.setText(null);
            //Snackbar.make(findViewById(android.R.id.content) , "Text", Snackbar.LENGTH_SHORT).setAction("Action", null).show();
            break;
        case (R.id.quit):
             finish();
             break;
    }

    return super.onOptionsItemSelected(item);
}

它没有反应。

【问题讨论】:

    标签: snackbar


    【解决方案1】:

    您可以使用主活动视图来显示 SnackBar:

    Snackbar.make(this.findViewById(android.R.id.content),
                    "FooBar", Snackbar.LENGTH_LONG).setAction("Action", null).show();
    

    【讨论】:

      【解决方案2】:

      当你点击菜单项时,你可以这样做: Snackbar.make(getWindow().getDecorView(), .....);

      请记住,您必须传递 View 对象才能显示小吃吧

      【讨论】:

        猜你喜欢
        • 2012-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-11
        • 2012-04-03
        • 1970-01-01
        相关资源
        最近更新 更多