Set Toast Appear Length

前端 未结 7 2017
梦毁少年i
梦毁少年i 2020-12-02 07:47

Is there anyway I can tell a Toast Notification to show up only for a specified amount of time. Generally shorter then a regular toast message.

相关标签:
7条回答
  • 2020-12-02 08:48

    //try it

        public void myToast(String message) {
        LayoutInflater myInflator = getLayoutInflater();
        View myLayout = myInflator.inflate(R.layout.custom_layout,
                (ViewGroup) findViewById(R.id.toastlayout));
        TextView myMessage = (TextView) myLayout.findViewById(R.id.label);
        myMessage.setText(message);
        Toast toast = new Toast(getApplicationContext());
        toast.setView(myLayout);
        toast.setDuration(400);
        myMessage.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL
                | Gravity.CENTER_VERTICAL);
        toast.show();
    }
    
    0 讨论(0)
提交回复
热议问题