How to display Toast at center of screen

后端 未结 8 1797
北荒
北荒 2021-01-30 09:48

In Android I want to display a toast message at the bottom of the screen, I tried this:

Toast.makeText(test.this,\"bbb\", Toast.LENGTH_LONG).show();
相关标签:
8条回答
  • 2021-01-30 10:23

    In Xamarin.Android, this displays toast at center of screen:

                Toast toast = Toast.MakeText(ApplicationContext, "bbb", ToastLength.Long);
                toast.SetGravity(GravityFlags.Center, 0, 0);
                toast.Show();
    
    0 讨论(0)
  • 2021-01-30 10:26
    Toast toast = new Toast(context);
            toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
    toast.show();
    
    0 讨论(0)
  • 2021-01-30 10:26

    Showing/ Setting text gravity at center (Horizontally) in koltin

    fun Context.longToast(msg: String) {
        Toast.makeText(this, msg, Toast.LENGTH_LONG)
            .apply {
               view.findViewById<TextView>(android.R.id.message)?.gravity = Gravity.CENTER
            }
            .show()
    }
    
    0 讨论(0)
  • 2021-01-30 10:30

    The following code can be used to display Toast message

    Toast tt = Toast.makeText(MainActivity.this,"Your text displayed here", Toast.LENGTH_LONG);
    tt.setGravity(Gravity.CENTER, 0, 0);
    tt.show();
    
    0 讨论(0)
  • 2021-01-30 10:34

    To display the Toast in center of the screen.

    Toast toast = Toast.makeText(test.this,"bbb", Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER, 0, 0);
    toast.show();
    
    0 讨论(0)
  • 2021-01-30 10:34

    The below code worked for me.

    Toast.makeText(this, "Toast in center", Toast.LENGTH_SHORT).setGravity(Gravity.CENTER,0,0).show();
    
    0 讨论(0)
提交回复
热议问题