Merge pull request #73 from Telerik-Verified-Plugins/master

Style the text color
This commit is contained in:
Eddy Verbruggen 2016-02-17 19:50:05 +01:00
commit ffe056db75
5 changed files with 20 additions and 5 deletions

View File

@ -226,6 +226,7 @@ Note that on WP this object is currently ignored.
styling: {
opacity: 0.75, // 0.0 (transparent) to 1.0 (opaque). Default 0.8
backgroundColor: '#FF0000', // make sure you use #RRGGBB. Default #333333
textColor: '#FFFF00', // Ditto. Default #FFFFFF
cornerRadius: 16, // minimum is 0 (square). iOS default 20, Android default 100
horizontalPadding: 20, // iOS default 16, Android default 50
verticalPadding: 16 // iOS default 12, Android default 30
@ -250,6 +251,7 @@ The Android code was entirely created by me.
For iOS most credits go to this excellent [Toast for iOS project by Charles Scalesse] (https://github.com/scalessec/Toast).
## 6. CHANGELOG
- 2.4.1: As an addition to 2.4.0, [Sino](https://github.com/SinoBoeckmann) added the option to change the text color!
- 2.4.0: You can now style the Toast with a number of properties. See
- 2.3.2: The click event introduced with 2.3.0 did not work with Android 5+.
- 2.3.0: The plugin will now report back to JS if Toasts were tapped by the user.

View File

@ -1,6 +1,6 @@
{
"name": "cordova-plugin-x-toast",
"version": "2.4.0",
"version": "2.4.1",
"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",

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.4.0">
id="nl.x-services.plugins.toast"
version="2.4.1">
<name>Toast</name>

View File

@ -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

View File

@ -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 = theTitleLabelTextColor;
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;