|
6 | 6 | import android.content.Context; |
7 | 7 | import android.util.DisplayMetrics; |
8 | 8 | import android.util.Log; |
| 9 | +import android.view.Gravity; |
9 | 10 | import android.view.View; |
10 | 11 | import android.view.ViewGroup; |
11 | 12 | import android.widget.TextView; |
@@ -138,6 +139,7 @@ private void displaySnackbar(View view, ReadableMap options, final Callback call |
138 | 139 | int duration = getOptionValue(options, "duration", Snackbar.LENGTH_SHORT); |
139 | 140 | int numberOfLines = getOptionValue(options, "numberOfLines", 2); |
140 | 141 | int textColor = getOptionValue(options, "textColor", Color.WHITE); |
| 142 | + boolean textAlignCenter = getOptionValue(options, "textAlignCenter", false); |
141 | 143 | boolean rtl = getOptionValue(options, "rtl", false); |
142 | 144 | int marginBottom = getOptionValue(options, "marginBottom", 0); |
143 | 145 | String fontFamily = getOptionValue(options, "fontFamily", null); |
@@ -179,6 +181,19 @@ private void displaySnackbar(View view, ReadableMap options, final Callback call |
179 | 181 | TextView snackbarText = snackbarView.findViewById(com.google.android.material.R.id.snackbar_text); |
180 | 182 | snackbarText.setMaxLines(numberOfLines); |
181 | 183 | snackbarText.setTextColor(textColor); |
| 184 | + if (textAlignCenter) { |
| 185 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ |
| 186 | + snackbarText.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
| 187 | + } else { |
| 188 | + snackbarText.setGravity(Gravity.CENTER_HORIZONTAL); |
| 189 | + } |
| 190 | + } else { |
| 191 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ |
| 192 | + snackbarText.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); |
| 193 | + } else { |
| 194 | + snackbarText.setGravity(Gravity.START); |
| 195 | + } |
| 196 | + } |
182 | 197 |
|
183 | 198 | if (font != null) { |
184 | 199 | snackbarText.setTypeface(font); |
|
0 commit comments