mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2025-02-24 18:52:51 +08:00
Merge pull request #2 from ergowerk/master
Allow the user set a textColor
This commit is contained in:
commit
37c14a6d2d
@ -7,6 +7,7 @@ import android.view.Gravity;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.CordovaPlugin;
|
||||||
@ -92,6 +93,7 @@ public class Toast extends CordovaPlugin {
|
|||||||
|
|
||||||
// the defaults mimic the default toast as close as possible
|
// the defaults mimic the default toast as close as possible
|
||||||
final String backgroundColor = styling.optString("backgroundColor", "#333333");
|
final String backgroundColor = styling.optString("backgroundColor", "#333333");
|
||||||
|
final String textColor = styling.optString("textColor", "#ffffff");
|
||||||
final double opacity = styling.optDouble("opacity", 0.8);
|
final double opacity = styling.optDouble("opacity", 0.8);
|
||||||
final int cornerRadius = styling.optInt("cornerRadius", 100);
|
final int cornerRadius = styling.optInt("cornerRadius", 100);
|
||||||
final int horizontalPadding = styling.optInt("horizontalPadding", 50);
|
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.setAlpha((int)(opacity * 255)); // 0-255, where 0 is an invisible background
|
||||||
shape.setColor(Color.parseColor(backgroundColor));
|
shape.setColor(Color.parseColor(backgroundColor));
|
||||||
toast.getView().setBackground(shape);
|
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);
|
toast.getView().setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
|
||||||
|
|
||||||
// this gives the toast a very subtle shadow on newer devices
|
// this gives the toast a very subtle shadow on newer devices
|
||||||
|
@ -347,12 +347,15 @@ static id styling;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (title != nil) {
|
if (title != nil) {
|
||||||
|
NSString * titleLabelTextColor = styling[@"textColor"];
|
||||||
|
UIColor *theTitleLabelTextColor = titleLabelTextColor == nil ? [UIColor whiteColor] : [self colorFromHexString:titleLabelTextColor];
|
||||||
|
|
||||||
titleLabel = [[UILabel alloc] init];
|
titleLabel = [[UILabel alloc] init];
|
||||||
titleLabel.numberOfLines = CSToastMaxTitleLines;
|
titleLabel.numberOfLines = CSToastMaxTitleLines;
|
||||||
titleLabel.font = [UIFont boldSystemFontOfSize:CSToastFontSize];
|
titleLabel.font = [UIFont boldSystemFontOfSize:CSToastFontSize];
|
||||||
titleLabel.textAlignment = NSTextAlignmentLeft;
|
titleLabel.textAlignment = NSTextAlignmentLeft;
|
||||||
titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
titleLabel.textColor = [UIColor whiteColor];
|
titleLabel.textColor = titleLabelTextColor;
|
||||||
titleLabel.backgroundColor = [UIColor clearColor];
|
titleLabel.backgroundColor = [UIColor clearColor];
|
||||||
titleLabel.alpha = 1.0;
|
titleLabel.alpha = 1.0;
|
||||||
titleLabel.text = title;
|
titleLabel.text = title;
|
||||||
@ -364,11 +367,14 @@ static id styling;
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (message != nil) {
|
if (message != nil) {
|
||||||
|
NSString * messageLabelTextColor = styling[@"textColor"];
|
||||||
|
UIColor *theMessageLabelTextColor = messageLabelTextColor == nil ? [UIColor whiteColor] : [self colorFromHexString:messageLabelTextColor];
|
||||||
|
|
||||||
messageLabel = [[UILabel alloc] init];
|
messageLabel = [[UILabel alloc] init];
|
||||||
messageLabel.numberOfLines = CSToastMaxMessageLines;
|
messageLabel.numberOfLines = CSToastMaxMessageLines;
|
||||||
messageLabel.font = [UIFont systemFontOfSize:CSToastFontSize];
|
messageLabel.font = [UIFont systemFontOfSize:CSToastFontSize];
|
||||||
messageLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
messageLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||||
messageLabel.textColor = [UIColor whiteColor];
|
messageLabel.textColor = theMessageLabelTextColor;
|
||||||
messageLabel.backgroundColor = [UIColor clearColor];
|
messageLabel.backgroundColor = [UIColor clearColor];
|
||||||
messageLabel.alpha = 1.0;
|
messageLabel.alpha = 1.0;
|
||||||
messageLabel.text = message;
|
messageLabel.text = message;
|
||||||
|
Loading…
Reference in New Issue
Block a user