mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2025-04-29 06:56:08 +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",
|
"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.",
|
"description": "This plugin allows you to show a Toast. A Toast is a little non intrusive buttonless popup which automatically disappears.",
|
||||||
"cordova": {
|
"cordova": {
|
||||||
"id": "cordova-plugin-x-toast",
|
"id": "cordova-plugin-x-toast",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="cordova-plugin-x-toast"
|
id="cordova-plugin-x-toast"
|
||||||
version="2.2.2">
|
version="2.2.3">
|
||||||
|
|
||||||
<name>Toast</name>
|
<name>Toast</name>
|
||||||
|
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package nl.xservices.plugins;
|
package nl.xservices.plugins;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.CordovaPlugin;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
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 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
|
// TODO also look at https://github.com/JohnPersano/Supertoasts
|
||||||
@ -53,13 +57,16 @@ public class Toast extends CordovaPlugin {
|
|||||||
cordova.getActivity().runOnUiThread(new Runnable() {
|
cordova.getActivity().runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
android.widget.Toast toast = android.widget.Toast.makeText(
|
android.widget.Toast toast = android.widget.Toast.makeText(
|
||||||
cordova.getActivity().getWindow().getContext(),
|
// cordova.getActivity().getWindow().getContext(),
|
||||||
|
cordova.getActivity().getApplicationContext(),
|
||||||
message,
|
message,
|
||||||
"short".equals(duration) ? android.widget.Toast.LENGTH_SHORT : android.widget.Toast.LENGTH_LONG);
|
"short".equals(duration) ? android.widget.Toast.LENGTH_SHORT : android.widget.Toast.LENGTH_LONG);
|
||||||
|
|
||||||
// toast.getView().setBackgroundColor(Color.GRAY);
|
try {
|
||||||
// toast.getView().setPadding(20, 10, 20, 10);
|
final Method setTintMethod = Drawable.class.getMethod("setTint", int.class);
|
||||||
toast.getView().getBackground().setTint(Color.DKGRAY);
|
setTintMethod.invoke(toast.getView().getBackground(), Color.DKGRAY);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
if ("top".equals(position)) {
|
if ("top".equals(position)) {
|
||||||
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 20 + addPixelsY);
|
toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 20 + addPixelsY);
|
||||||
} else if ("bottom".equals(position)) {
|
} else if ("bottom".equals(position)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user