diff --git a/package.json b/package.json index 814f9ad..8ab1122 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-x-toast", - "version": "2.2.2", + "version": "2.2.3", "description": "This plugin allows you to show a Toast. A Toast is a little non intrusive buttonless popup which automatically disappears.", "cordova": { "id": "cordova-plugin-x-toast", diff --git a/plugin.xml b/plugin.xml index 1eee3de..eed502e 100755 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="2.2.3"> Toast diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index 20f8cdf..f9d9f9c 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -1,13 +1,17 @@ package nl.xservices.plugins; import android.graphics.Color; +import android.graphics.drawable.Drawable; import android.view.Gravity; + import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.lang.reflect.Method; + /* // TODO nice way for the Toast plugin to offer a longer delay than the default short and long options // TODO also look at https://github.com/JohnPersano/Supertoasts @@ -53,13 +57,16 @@ public class Toast extends CordovaPlugin { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { android.widget.Toast toast = android.widget.Toast.makeText( - cordova.getActivity().getWindow().getContext(), +// cordova.getActivity().getWindow().getContext(), + cordova.getActivity().getApplicationContext(), message, "short".equals(duration) ? android.widget.Toast.LENGTH_SHORT : android.widget.Toast.LENGTH_LONG); -// toast.getView().setBackgroundColor(Color.GRAY); -// toast.getView().setPadding(20, 10, 20, 10); - toast.getView().getBackground().setTint(Color.DKGRAY); + try { + final Method setTintMethod = Drawable.class.getMethod("setTint", int.class); + setTintMethod.invoke(toast.getView().getBackground(), Color.DKGRAY); + } catch (Exception ignore) { + } if ("top".equals(position)) { toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 20 + addPixelsY); } else if ("bottom".equals(position)) {