How to style the standard react-native android picker?
It can be styled via native android. See this and this.
Add the following code to /res/values/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
</style>
<style name="SpinnerItem" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textSize">18dp</item>
</style>
<style name="SpinnerDropDownItem" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">18dp</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:gravity">center</item>
<item name="android:background">@drawable/mydivider</item>
</style>
Create a file at res/drawable/mydivider.xml
and add the following code
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#29A1C9" />
<corners android:radius="0.5dp" />
<stroke
android:color="#FFFFFF"
android:width="0.1dp" />
</shape>
Before styling:
After styling:
React Native Picker Styling - ANDROID
Picker and Picker item's styling is handled natively on Android. You need to define style for Android's SpinnerItem in android/app/src/res/styles.xml
see: How to style the standard react-native android picker?
I tried to test the underline but couldn't seem to find anything that worked. Here is couple of workarounds Android spinner with underline appcompat
However, I would simply use react native's components to our advantage. I'd create a new component that wraps React Native's Picker and put the picker in a View with the underline style that renders a placeholder if the Picker's value is undefined.
How to style the react-native picker using android styles.xml?
That's because you need to declare the styles inside your AppTheme
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
<item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
</style>
<style name="SpinnerItem">
<item name="android:textColor">#ffffff</item>
<item name="android:background">#993399</item>
</style>
<style name="SpinnerDropDownItem">
<item name="android:textColor">#ffffff</item>
<item name="android:background">#993399</item>
</style>
</resources>
That's it :)
Related Topics
Eclipse/Android:"Errors Running Builder 'Android Pre Compiler' on Project..."
Why Do I Get Com.Google.Android.Gms.Common.Api.Apiexception: 10:
Set Selected Item in Android Bottomnavigationview
Differencebetween Activity and Context
Gradle Dsl Method Not Found: 'Compile()'
Getresources().Getcolor() Is Deprecated
How to Get Unique Device Hardware Id in Android
Menuitemcompat.Getactionview Always Returns Null
Android, How to Not Destroy the Activity When I Rotate the Device
How to Know My Android Application Has Been Upgraded in Order to Reset an Alarm
Duplicate Files Copied (Android Studio 0.4.0)
Incompatible Plugins for Android-Apt After Upgrading to Android Studio 2.3
Adb Is Not Recognized as Internal or External Command on Windows
How to Disable Instant Run for Android Studio 3.0
What Does Ellipsize Mean in Android
Publish an Android Library to Maven with Aar and Sources Jar