-4

I am using a android toast message to display a message to the user but the duration even when set to _LENGTH_LONG seems not enough. I would like to try a SnackBar or any other display method but i am stuck. How can i apply that? This is my code.

@Override
    protected void onPostExecute(String  result) {

        Toast toast = Toast.makeText(ctx, result, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.TOP, 0, 130);
        toast.show();

    }

How can i replace this toast with something like a snackbar or a message box that will set it to display for a longer time, say 1 minute?

Ankita Shah
  • 1,866
  • 16
  • 31

3 Answers3

0

Pretty similar:

 import android.support.design.widget.Snackbar;
    ...
    coordinatorLayout = (CoordinatorLayout) findViewById(R.id
                    .coordinatorLayout);
    Snackbar snackbar = Snackbar.make(coordinatorLayout, "MESSAGE", Snackbar.LENGTH_LONG);
    snackbar.show();
0

try this.

String message;
            int color;
            message = "hello";
            color = Color.RED;
            Snackbar snackbar = Snackbar.make(findViewById(R.id.btn), message, Snackbar.LENGTH_LONG);

            View sbView = snackbar.getView();
            TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
            textView.setTextColor(color);
            snackbar.show();

Button b1 = (Button) findViewById(R.id.btn);

appy
  • 106
  • 1
  • 5
0

Make an activity and get the view in onCreate(bundle) and Define a AsyncTask as inner class and do like this

@Override
    protected void onPostExecute(String  result) {

// check view is not null

if(view!=null){

int durationInMills=60000;//your duration

String msg="Your Message";

Snackbar.make(view,msg,durationInMills).show();

}

}