diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index 580daac..1232c7a 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -7,6 +7,7 @@ import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaPlugin; @@ -92,6 +93,7 @@ public class Toast extends CordovaPlugin { // the defaults mimic the default toast as close as possible final String backgroundColor = styling.optString("backgroundColor", "#333333"); + final String textColor = styling.optString("textColor", "#ffffff"); final double opacity = styling.optDouble("opacity", 0.8); final int cornerRadius = styling.optInt("cornerRadius", 100); final int horizontalPadding = styling.optInt("horizontalPadding", 50); @@ -102,6 +104,11 @@ public class Toast extends CordovaPlugin { shape.setAlpha((int)(opacity * 255)); // 0-255, where 0 is an invisible background shape.setColor(Color.parseColor(backgroundColor)); toast.getView().setBackground(shape); + + final TextView toastTextView; + toastTextView = (TextView) toast.getView().findViewById(android.R.id.message); + toastTextView.setTextColor(Color.parseColor(textColor)); + toast.getView().setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); // this gives the toast a very subtle shadow on newer devices diff --git a/src/ios/Toast+UIView.m b/src/ios/Toast+UIView.m index 4d4cf1b..ea613b1 100644 --- a/src/ios/Toast+UIView.m +++ b/src/ios/Toast+UIView.m @@ -347,12 +347,15 @@ static id styling; } if (title != nil) { + NSString * titleLabelTextColor = styling[@"textColor"]; + UIColor *theTitleLabelTextColor = titleLabelTextColor == nil ? [UIColor whiteColor] : [self colorFromHexString:titleLabelTextColor]; + titleLabel = [[UILabel alloc] init]; titleLabel.numberOfLines = CSToastMaxTitleLines; titleLabel.font = [UIFont boldSystemFontOfSize:CSToastFontSize]; titleLabel.textAlignment = NSTextAlignmentLeft; titleLabel.lineBreakMode = NSLineBreakByWordWrapping; - titleLabel.textColor = [UIColor whiteColor]; + titleLabel.textColor = titleLabelTextColor; titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.alpha = 1.0; titleLabel.text = title; @@ -364,11 +367,14 @@ static id styling; } if (message != nil) { + NSString * messageLabelTextColor = styling[@"textColor"]; + UIColor *theMessageLabelTextColor = messageLabelTextColor == nil ? [UIColor whiteColor] : [self colorFromHexString:messageLabelTextColor]; + messageLabel = [[UILabel alloc] init]; messageLabel.numberOfLines = CSToastMaxMessageLines; messageLabel.font = [UIFont systemFontOfSize:CSToastFontSize]; messageLabel.lineBreakMode = NSLineBreakByWordWrapping; - messageLabel.textColor = [UIColor whiteColor]; + messageLabel.textColor = theMessageLabelTextColor; messageLabel.backgroundColor = [UIColor clearColor]; messageLabel.alpha = 1.0; messageLabel.text = message;