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.
This commit is contained in:
parent
f8887dc45e
commit
ecb47ab110
@ -1,7 +1,6 @@
|
||||
package nl.xservices.plugins;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.view.Gravity;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
@ -10,8 +9,6 @@ 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
|
||||
@ -29,6 +26,8 @@ public class Toast extends CordovaPlugin {
|
||||
|
||||
private android.widget.Toast mostRecentToast;
|
||||
|
||||
private static final boolean IS_AT_LEAST_ANDROID5 = Build.VERSION.SDK_INT >= 21;
|
||||
|
||||
// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
|
||||
private boolean isPaused;
|
||||
|
||||
@ -57,16 +56,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().getApplicationContext(),
|
||||
IS_AT_LEAST_ANDROID5 ? cordova.getActivity().getWindow().getContext() : cordova.getActivity().getApplicationContext(),
|
||||
message,
|
||||
"short".equals(duration) ? android.widget.Toast.LENGTH_SHORT : android.widget.Toast.LENGTH_LONG);
|
||||
|
||||
try {
|
||||
final Method setTintMethod = Drawable.class.getMethod("setTint", int.class);
|
||||
setTintMethod.invoke(toast.getView().getBackground(), Color.DKGRAY);
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
// if we want to change the background color some day, we can use this
|
||||
// try {
|
||||
// final Method setTintMethod = Drawable.class.getMethod("setTint", int.class);
|
||||
// setTintMethod.invoke(toast.getView().getBackground(), Color.RED); // default is 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