mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2025-02-24 02:02:51 +08:00
#60 Is it possible to change the android theme? Compatibility with older Android versions.
#61 Android exception NoSuchMethodError setTint.
This commit is contained in:
parent
273334664a
commit
f8887dc45e
@ -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",
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user