Skip to content

Commit

Permalink
Merge pull request #19 from EddyVerbruggen/master
Browse files Browse the repository at this point in the history
Center-align text on Android
  • Loading branch information
hypery2k committed Jan 3, 2017
2 parents 817dd7e + 7ce1109 commit 0153631
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion toast.android.js
Expand Up @@ -9,7 +9,15 @@ function makeText(text, duration) {
throw new Error("The `text` parameter is missing.");
}
var d = (typeof (duration) === "string" && duration[0] === "l") ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
return Toast.makeText(application.android.context, text, d);

var centeredText = new android.text.SpannableString(text);
centeredText.setSpan(
new android.text.style.AlignmentSpan.Standard(android.text.Layout.Alignment.ALIGN_CENTER),
0,
text.length - 1,
android.text.Spannable.SPAN_INCLUSIVE_INCLUSIVE);

return Toast.makeText(application.android.context, centeredText, d);
}

exports.makeText = makeText;

0 comments on commit 0153631

Please sign in to comment.