问题
I have made some code for my google map, where I position the camera to one place when the camera is positioned to the first place I toast a message and then I move the camera to another position but the problem is that the toast action doesn't appear for enough time in order to read the message. Is there anyway so I can set the toast lets say for 10 seconds or so ? Here is my code.
public void onFinish() {
LatLng 1= new LatLng(x , y);
LatLng 2= new LatLng(x , y);
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.animateCamera(CameraUpdateFactory.zoomTo(10), 30000,null);
Toast.makeText(getBaseContext(), " I want this message to displayed for 10 seconds.",
Toast.LENGTH_SHORT)
.show();
CameraPosition cameraPosition3 = new CameraPosition.Builder()
.target(1)
.zoom(16)
.bearing(300)
.tilt(30)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition3 ),30000,new
CancelableCallback()
{ public void onFinish() {
LatLng 2= new LatLng(x, y);
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.animateCamera(CameraUpdateFactory.zoomTo(10), 30000,null);
Toast.makeText(getBaseContext(), " This message for 10 seconds.", Toast.LENGTH_SHORT)
CameraPosition cameraPosition3 = new CameraPosition.Builder()
.target(2)
.zoom(16)
.bearing(300)
.tilt(30)
.build();
map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition3 ),30000,null);
回答1:
Try this surely it will help you i already tried it
final Toast toast = Toast.makeText(getBaseContext(), "YOUR MESSAGE",Toast.LENGTH_SHORT);
toast.show();
new CountDownTimer(10000, 1000)
{
public void onTick(long millisUntilFinished) {toast.show();}
public void onFinish() {toast.cancel();}
}.start();
got the answer from this question please refer for full details
http://stackoverflow.com/questions/2220560/can-an-android-toast-be-longer-than-toast-length-long
回答2:
You'll need to subclass the Toast class and use it. The default class has just two values. Even if you pass a longer time duration, it will we reverted to either of SHORT or LONG
回答3:
And this is your toast message in the 1000 is 1 seconds and then that 3rd position is the timing of your toast and then you can show te toast for 10 seconds ...
Toast.makeText(getBaseContext(), " This message for 10 seconds.", 10*1000).show();
来源:https://stackoverflow.com/questions/22806166/how-to-toast-a-message-for-a-specific-time-period