diff --git a/README.md b/README.md index dc7b0e1..5f2326b 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ You can copy-paste these lines of code for a quick test: ``` -#### Tweaking the vertical position (iOS only for now) +#### Tweaking the vertical position (iOS and Android) Since 2.1.0 you can add pixels to move the toast up or down. Note that `showWithOptions` can be used instead of the functions above, but it's not useful unless you want to pass `addPixelsY`. ```js diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index dffece4..cd97d5f 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -47,6 +47,7 @@ public class Toast extends CordovaPlugin { final String message = options.getString("message"); final String duration = options.getString("duration"); final String position = options.getString("position"); + final int addPixelsY = options.has("addPixelsY") ? options.getInt("addPixelsY") : 0; cordova.getActivity().runOnUiThread(new Runnable() { public void run() { @@ -56,11 +57,11 @@ public class Toast extends CordovaPlugin { "short".equals(duration) ? android.widget.Toast.LENGTH_SHORT : android.widget.Toast.LENGTH_LONG); if ("top".equals(position)) { - toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 20); + toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 20 + addPixelsY); } else if ("bottom".equals(position)) { - toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 20); + toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 20 - addPixelsY); } else if ("center".equals(position)) { - toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0); + toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, addPixelsY); } else { callbackContext.error("invalid position. valid options are 'top', 'center' and 'bottom'"); return;