Commit 499a1790 by zhangyuwan0

let default Toast can setting gravity.

parent 7a57759d
...@@ -43,6 +43,18 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -43,6 +43,18 @@ public class FluttertoastPlugin implements MethodCallHandler {
Number textcolor = call.argument("textcolor"); Number textcolor = call.argument("textcolor");
Number textSize = call.argument("fontSize"); Number textSize = call.argument("fontSize");
Integer realGravity;
switch (gravity) {
case "top":
realGravity = Gravity.TOP;
break;
case "center":
realGravity = Gravity.CENTER;
break;
default:
realGravity = Gravity.BOTTOM;
}
if(bgcolor != null && textcolor != null && textSize != null) { if(bgcolor != null && textcolor != null && textSize != null) {
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast_custom, null); View layout = inflater.inflate(R.layout.toast_custom, null);
...@@ -62,17 +74,6 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -62,17 +74,6 @@ public class FluttertoastPlugin implements MethodCallHandler {
toast.setView(layout); toast.setView(layout);
switch (gravity) {
case "top":
toast.setGravity(Gravity.TOP, 0, 100);
break;
case "center":
toast.setGravity(Gravity.CENTER, 0, 0);
break;
default:
toast.setGravity(Gravity.BOTTOM, 0, 100);
}
if (textSize != null) if (textSize != null)
text.setTextSize(textSize.floatValue()); text.setTextSize(textSize.floatValue());
...@@ -112,6 +113,7 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -112,6 +113,7 @@ public class FluttertoastPlugin implements MethodCallHandler {
text.setTextColor(textcolor.intValue()); text.setTextColor(textcolor.intValue());
} }
toast.setGravity(realGravity,0,0);
toast.show(); toast.show();
} else { } else {
int toastLength; int toastLength;
...@@ -121,11 +123,11 @@ public class FluttertoastPlugin implements MethodCallHandler { ...@@ -121,11 +123,11 @@ public class FluttertoastPlugin implements MethodCallHandler {
toastLength = Toast.LENGTH_SHORT; toastLength = Toast.LENGTH_SHORT;
} }
Toast toast = Toast.makeText(ctx, msg, toastLength); Toast toast = Toast.makeText(ctx, msg, toastLength);
toast.setGravity(realGravity,0,0);
toast.show(); toast.show();
} }
result.success(true); result.success(true);
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment