#60 Is it possible to change the android theme? Compatibility with older Android versions.

#61 Android exception NoSuchMethodError setTint.
This commit is contained in:
EddyVerbruggen 2015-12-01 08:59:43 +01:00
parent 273334664a
commit f8887dc45e
3 changed files with 13 additions and 6 deletions

View File

@ -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",

View File

@ -2,7 +2,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-plugin-x-toast"
version="2.2.2">
version="2.2.3">
<name>Toast</name>

View File

@ -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)) {