Open sebj54 opened 3 years ago
Hi @triniwiz, just to let you know: I found a solution to change style of the Stripe inputs.
Here is the complete solution:
Add a layout for the CardMultilineWidget
:
app/App_Resources/Android/src/main/res/layout/card_multiline_widget.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.stripe.android.view.CardNumberTextInputLayout
android:id="@+id/tl_card_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/acc_label_card_number"
android:layout_marginTop="@dimen/stripe_add_card_element_vertical_margin"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayout"
app:hintTextAppearance="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayoutAppearance"
android:textColorHint="@color/stripe_hint_color">
<com.stripe.android.view.CardNumberEditText
android:id="@+id/et_card_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/stripe_card_icon_multiline_padding"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/et_expiry"
android:nextFocusForward="@+id/et_expiry"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInput" />
</com.stripe.android.view.CardNumberTextInputLayout>
<LinearLayout
android:id="@+id/second_row_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="true"
android:gravity="bottom"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tl_expiry"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/stripe_add_card_element_vertical_margin"
android:layout_marginEnd="@dimen/stripe_add_card_expiry_middle_margin"
android:layout_weight="1"
android:hint="@string/acc_label_expiry_date"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayout"
app:hintTextAppearance="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayoutAppearance"
android:textColorHint="@color/stripe_hint_color">
<com.stripe.android.view.ExpiryDateEditText
android:id="@+id/et_expiry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:digits="@string/stripe_expiration_date_allowlist"
android:nextFocusDown="@+id/et_cvc"
android:nextFocusForward="@+id/et_cvc"
android:minHeight="@dimen/stripe_cmw_edit_text_minheight"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInput" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tl_cvc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/stripe_add_card_element_vertical_margin"
android:layout_marginEnd="@dimen/stripe_add_card_expiry_middle_margin"
android:layout_weight="1"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayout"
app:hintTextAppearance="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayoutAppearance"
android:textColorHint="@color/stripe_hint_color">
<com.stripe.android.view.CvcEditText
android:id="@+id/et_cvc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:nextFocusDown="@+id/et_postal_code"
android:nextFocusForward="@+id/et_postal_code"
android:minHeight="@dimen/stripe_cmw_edit_text_minheight"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInput" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tl_postal_code"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="@dimen/stripe_add_card_element_vertical_margin"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayout"
app:hintTextAppearance="@style/MyApp.Stripe.CardMultilineWidget.TextInputLayoutAppearance"
android:textColorHint="@color/stripe_hint_color">
<com.stripe.android.view.PostalCodeEditText
android:id="@+id/et_postal_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:minHeight="@dimen/stripe_cmw_edit_text_minheight"
style="@style/MyApp.Stripe.CardMultilineWidget.TextInput" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</merge>
Add the desired styles at the end of the existing styles.xml
file:
app/App_Resources/Android/src/main/res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!-- your existing styles -->
<style name="NativeScriptToolbarStyle" parent="NativeScriptToolbarStyleBase">
</style>
<style name="MyApp.Stripe.CardMultilineWidget.TextInputLayout" parent="Stripe.CardMultilineWidget.TextInputLayout">
</style>
<style name="MyApp.Stripe.CardMultilineWidget.TextInputLayoutAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/ns_accent</item> <!-- label focused -->
</style>
<style name="MyApp.Stripe.CardMultilineWidget.TextInput" parent="StripeDefaultTheme">
<item name="android:textColor">@color/stripe_input_color</item> <!-- text color (value) -->
<item name="android:textColorHint">@color/stripe_hint_color</item> <!-- hint text color -->
<item name="backgroundTint">@color/stripe_hint_color</item> <!-- border bottom -->
<item name="android:textSize">18sp</item>
</style>
</resources>
Add the required dimensions:
app/App_Resources/Android/src/main/res/values/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="stripe_add_card_element_vertical_margin">12dp</dimen>
<dimen name="stripe_add_card_expiry_middle_margin">8dp</dimen>
<dimen name="stripe_card_icon_multiline_padding">8dp</dimen>
<dimen name="stripe_cmw_edit_text_minheight">48dp</dimen>
</resources>
Add the desired colors
app/App_Resources/Android/src/main/res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- your existing colors -->
<color name="stripe_input_color">#01103b</color>
<color name="stripe_hint_color">#7d869d</color>
</resources>
Add dark mode colors if you want
app/App_Resources/Android/src/main/res/values-night/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="stripe_input_color">#ffffff</color>
<color name="stripe_hint_color">#e6e6e6</color>
</resources>
If anyone wants to go further, here are some useful resources which helped me a lot:
Hi there!
I've been using this plugin for a while and I've noticed that fields are shown black on black with dark mode. Here are some screenshots:
Do you know how I can change that color? Maybe with a hidden API?
It seems that Stripe does not provide a way to tweak colors with their Android SDK…
Maybe this has been fixed with Stripe SDK v16.4.0 (you are using 16.1.1).
As I don't know how to update an Android dependency, feel free to make me test anything ;)
Thanks for your help!