How to set shadows in React Native for android?









up vote
37
down vote

favorite
12












Hi am trying to set a shadow for my fab but my attempts has failed so far i tried setting shadow props but that is for ios only so i tried to play with elevation property but it doesn't look right.



Here's what i tried



<View style=width: 56, height: 56, elevation: 2, borderRadius: 28, marginBottom: 3, backgroundColor: 'rgba(231,76,60,1)'></View>


What i need to achieve



enter image description here










share|improve this question

























    up vote
    37
    down vote

    favorite
    12












    Hi am trying to set a shadow for my fab but my attempts has failed so far i tried setting shadow props but that is for ios only so i tried to play with elevation property but it doesn't look right.



    Here's what i tried



    <View style=width: 56, height: 56, elevation: 2, borderRadius: 28, marginBottom: 3, backgroundColor: 'rgba(231,76,60,1)'></View>


    What i need to achieve



    enter image description here










    share|improve this question























      up vote
      37
      down vote

      favorite
      12









      up vote
      37
      down vote

      favorite
      12






      12





      Hi am trying to set a shadow for my fab but my attempts has failed so far i tried setting shadow props but that is for ios only so i tried to play with elevation property but it doesn't look right.



      Here's what i tried



      <View style=width: 56, height: 56, elevation: 2, borderRadius: 28, marginBottom: 3, backgroundColor: 'rgba(231,76,60,1)'></View>


      What i need to achieve



      enter image description here










      share|improve this question













      Hi am trying to set a shadow for my fab but my attempts has failed so far i tried setting shadow props but that is for ios only so i tried to play with elevation property but it doesn't look right.



      Here's what i tried



      <View style=width: 56, height: 56, elevation: 2, borderRadius: 28, marginBottom: 3, backgroundColor: 'rgba(231,76,60,1)'></View>


      What i need to achieve



      enter image description here







      react-native






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 25 '16 at 9:46









      Ibrahim Ahmed

      5062627




      5062627






















          11 Answers
          11






          active

          oldest

          votes

















          up vote
          55
          down vote



          accepted
          +50










          UPDATE



          Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. See other answers.



          --



          One way to get shadows for android is to install react-native-shadow



          Example from the readme:



          import React, Component from 'react' import 
          StyleSheet,
          View,
          Text,
          ScrollView,
          Image,
          TouchableHighlight from 'react-native'

          import BoxShadow from 'react-native-shadow'

          export default class VideoCell extends Component
          render = () =>
          const shadowOpt =
          width:160,
          height:170,
          color:"#000",
          border:2,
          radius:3,
          opacity:0.2,
          x:0,
          y:3,
          style:marginVertical:5


          return (
          <BoxShadow setting=shadowOpt>
          <TouchableHighlight style=
          position:"relative",
          width: 160,
          height: 170,
          backgroundColor: "#fff",
          borderRadius:3,
          // marginVertical:5,
          overflow:"hidden">
          …………………………
          </TouchableHighlight>
          </BoxShadow>
          )







          share|improve this answer


















          • 2




            Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. I tested it with React Native 0.52
            – Guy
            Jan 15 at 3:41










          • Be careful when using elevation as it won't respect your settings for shadow, such as the color and offset.
            – cseelus
            Apr 5 at 17:55










          • this lib, how to do if I don't know the specify width height of children. . . cuz it require.
            – Leang Socheat
            Oct 23 at 3:03

















          up vote
          65
          down vote













          Another solution without using a third-party library is using elevation.



          Pulled from react-native documentation.
          https://facebook.github.io/react-native/docs/view.html




          (Android-only) Sets the elevation of a view, using Android's
          underlying elevation API. This adds a drop shadow to the item and
          affects z-order for overlapping views. Only supported on Android 5.0+,
          has no effect on earlier versions.




          elevation will go into the style property and it can be implemented like so.



          <View style= elevation: 2 >
          children
          </View>


          The higher the elevation, the bigger the shadow. Hope this helps!






          share|improve this answer




















          • why elevation attribute is written inside 2 braces?
            – divine
            Jun 24 '17 at 7:52






          • 5




            @divine the outer bracket is for JS interpolation, the inner is for an object
            – Asaf David
            Jun 25 '17 at 7:28






          • 3




            This only does a shadow on the bottom of a view, it doesn't allow you to do shadows on the other sides
            – Erich
            Aug 31 '17 at 18:41










          • Correct, there are many things iOS handles better when using react-native and shadows are one of them.
            – Ajackster
            Aug 31 '17 at 20:25






          • 2




            Note: this only works in Android 5.0+
            – Muhammad Riyaz
            Sep 8 '17 at 10:31

















          up vote
          29
          down vote













          You can try



          //ios 
          shadowOpacity: 0.3,
          shadowRadius: 3,
          shadowOffset:
          height: 0,
          width: 0
          ,
          //android
          elevation: 1





          share|improve this answer






















          • Elevation does not create a large enough or configurable shadow for android - react-native-shadow seems like the best option
            – evanjmg
            Mar 6 at 12:02

















          up vote
          5
          down vote













          Just use 'elevation' property to get shadow in android. something like below



          const Header = () => 
          // const textStyle, viewStyle = styles;
          return (
          <View style=styles.viewStyle>
          <Text style=styles.textStyle>Albums</Text>
          </View>
          )



          const styles =
          viewStyle:
          backgroundColor:'#f8f8f8',
          justifyContext:'center',
          alignItems: 'center',
          padding:16,
          elevation: 2







          share|improve this answer



























            up vote
            2
            down vote













            The following will help you to give each Platform the styling you want:



            import Text, View, Platform from 'react-native';

            ......
            <View style=styles.viewClass></View>
            ......


            const styles =
            viewClass:
            justifyContent: 'center',
            alignItems: 'center',
            height: 60,
            ...Platform.select(
            ios:
            shadowColor: '#000',
            shadowOffset: width: 0, height: 2 ,
            shadowOpacity: 0.2,
            ,
            android:
            elevation: 1

            ,
            ),

            ;





            share|improve this answer
















            • 2




              It's not needed to specify the platform since in iOS elevation property will be ignored
              – cody
              Jul 26 at 22:42










            • @cody yes, you are right! but my example shows how to set styles for different platforms.
              – Mohammed Alawneh
              Jul 29 at 7:12


















            up vote
            1
            down vote













            for an android screen you can use this property elevation.



            for example :



             HeaderView:
            backgroundColor:'#F8F8F8',
            justifyContent:'center',
            alignItems:'center',
            height:60,
            paddingTop:15,

            //Its for IOS
            shadowColor: '#000',
            shadowOffset: width: 0, height: 2 ,
            shadowOpacity: 0.2,

            // its for android
            elevation: 5,
            position:'relative',

            ,





            share|improve this answer





























              up vote
              0
              down vote













              elevation still no work in Expo v30 && React-native v0.55.4.
              I have tried the all answers here.



              Also, don't try react-native-shadow - their shadow rendering is terrible.
              So, I am continuing the research.






              share|improve this answer



























                up vote
                0
                down vote













                I have implemented CardView for react-native with elevation, that support android(All version) and iOS. Let me know is it help you or not. https://github.com/Kishanjvaghela/react-native-cardview



                import CardView from 'react-native-cardview'
                <CardView
                cardElevation=2
                cardMaxElevation=2
                cornerRadius=5>
                <Text>
                Elevation 0
                </Text>
                </CardView>


                enter image description here






                share|improve this answer



























                  up vote
                  0
                  down vote













                  In short, you can't do that in android, because if you see the docs about shadow only Support IOS see doc



                  The best option you can install 3rd party react-native-shadow






                  share|improve this answer



























                    up vote
                    0
                    down vote













                    Set elevation: 3 and you should see the shadow in bottom of component without a 3rd party lib. At least in RN 0.57.4






                    share|improve this answer



























                      up vote
                      0
                      down vote













                      I had the same problem shadow/elevation not showing on Android with elevation:2. Then i noticed that the view element is fool width, so I added margin:2 to the view element and elevation properly appeared.



                      Style:



                       margin: 2,
                      shadowColor: '#000',
                      shadowOffset:
                      width: 0,
                      height: 1
                      ,
                      shadowOpacity: 0.2,
                      shadowRadius: 1.41,
                      elevation: 2


                      Android:
                      enter image description here



                      iOS:
                      enter image description here






                      share|improve this answer




















                        Your Answer






                        StackExchange.ifUsing("editor", function ()
                        StackExchange.using("externalEditor", function ()
                        StackExchange.using("snippets", function ()
                        StackExchange.snippets.init();
                        );
                        );
                        , "code-snippets");

                        StackExchange.ready(function()
                        var channelOptions =
                        tags: "".split(" "),
                        id: "1"
                        ;
                        initTagRenderer("".split(" "), "".split(" "), channelOptions);

                        StackExchange.using("externalEditor", function()
                        // Have to fire editor after snippets, if snippets enabled
                        if (StackExchange.settings.snippets.snippetsEnabled)
                        StackExchange.using("snippets", function()
                        createEditor();
                        );

                        else
                        createEditor();

                        );

                        function createEditor()
                        StackExchange.prepareEditor(
                        heartbeatType: 'answer',
                        convertImagesToLinks: true,
                        noModals: true,
                        showLowRepImageUploadWarning: true,
                        reputationToPostImages: 10,
                        bindNavPrevention: true,
                        postfix: "",
                        imageUploader:
                        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                        allowUrls: true
                        ,
                        onDemand: true,
                        discardSelector: ".discard-answer"
                        ,immediatelyShowMarkdownHelp:true
                        );



                        );













                        draft saved

                        draft discarded


















                        StackExchange.ready(
                        function ()
                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41320131%2fhow-to-set-shadows-in-react-native-for-android%23new-answer', 'question_page');

                        );

                        Post as a guest















                        Required, but never shown

























                        11 Answers
                        11






                        active

                        oldest

                        votes








                        11 Answers
                        11






                        active

                        oldest

                        votes









                        active

                        oldest

                        votes






                        active

                        oldest

                        votes








                        up vote
                        55
                        down vote



                        accepted
                        +50










                        UPDATE



                        Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. See other answers.



                        --



                        One way to get shadows for android is to install react-native-shadow



                        Example from the readme:



                        import React, Component from 'react' import 
                        StyleSheet,
                        View,
                        Text,
                        ScrollView,
                        Image,
                        TouchableHighlight from 'react-native'

                        import BoxShadow from 'react-native-shadow'

                        export default class VideoCell extends Component
                        render = () =>
                        const shadowOpt =
                        width:160,
                        height:170,
                        color:"#000",
                        border:2,
                        radius:3,
                        opacity:0.2,
                        x:0,
                        y:3,
                        style:marginVertical:5


                        return (
                        <BoxShadow setting=shadowOpt>
                        <TouchableHighlight style=
                        position:"relative",
                        width: 160,
                        height: 170,
                        backgroundColor: "#fff",
                        borderRadius:3,
                        // marginVertical:5,
                        overflow:"hidden">
                        …………………………
                        </TouchableHighlight>
                        </BoxShadow>
                        )







                        share|improve this answer


















                        • 2




                          Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. I tested it with React Native 0.52
                          – Guy
                          Jan 15 at 3:41










                        • Be careful when using elevation as it won't respect your settings for shadow, such as the color and offset.
                          – cseelus
                          Apr 5 at 17:55










                        • this lib, how to do if I don't know the specify width height of children. . . cuz it require.
                          – Leang Socheat
                          Oct 23 at 3:03














                        up vote
                        55
                        down vote



                        accepted
                        +50










                        UPDATE



                        Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. See other answers.



                        --



                        One way to get shadows for android is to install react-native-shadow



                        Example from the readme:



                        import React, Component from 'react' import 
                        StyleSheet,
                        View,
                        Text,
                        ScrollView,
                        Image,
                        TouchableHighlight from 'react-native'

                        import BoxShadow from 'react-native-shadow'

                        export default class VideoCell extends Component
                        render = () =>
                        const shadowOpt =
                        width:160,
                        height:170,
                        color:"#000",
                        border:2,
                        radius:3,
                        opacity:0.2,
                        x:0,
                        y:3,
                        style:marginVertical:5


                        return (
                        <BoxShadow setting=shadowOpt>
                        <TouchableHighlight style=
                        position:"relative",
                        width: 160,
                        height: 170,
                        backgroundColor: "#fff",
                        borderRadius:3,
                        // marginVertical:5,
                        overflow:"hidden">
                        …………………………
                        </TouchableHighlight>
                        </BoxShadow>
                        )







                        share|improve this answer


















                        • 2




                          Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. I tested it with React Native 0.52
                          – Guy
                          Jan 15 at 3:41










                        • Be careful when using elevation as it won't respect your settings for shadow, such as the color and offset.
                          – cseelus
                          Apr 5 at 17:55










                        • this lib, how to do if I don't know the specify width height of children. . . cuz it require.
                          – Leang Socheat
                          Oct 23 at 3:03












                        up vote
                        55
                        down vote



                        accepted
                        +50







                        up vote
                        55
                        down vote



                        accepted
                        +50




                        +50




                        UPDATE



                        Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. See other answers.



                        --



                        One way to get shadows for android is to install react-native-shadow



                        Example from the readme:



                        import React, Component from 'react' import 
                        StyleSheet,
                        View,
                        Text,
                        ScrollView,
                        Image,
                        TouchableHighlight from 'react-native'

                        import BoxShadow from 'react-native-shadow'

                        export default class VideoCell extends Component
                        render = () =>
                        const shadowOpt =
                        width:160,
                        height:170,
                        color:"#000",
                        border:2,
                        radius:3,
                        opacity:0.2,
                        x:0,
                        y:3,
                        style:marginVertical:5


                        return (
                        <BoxShadow setting=shadowOpt>
                        <TouchableHighlight style=
                        position:"relative",
                        width: 160,
                        height: 170,
                        backgroundColor: "#fff",
                        borderRadius:3,
                        // marginVertical:5,
                        overflow:"hidden">
                        …………………………
                        </TouchableHighlight>
                        </BoxShadow>
                        )







                        share|improve this answer














                        UPDATE



                        Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. See other answers.



                        --



                        One way to get shadows for android is to install react-native-shadow



                        Example from the readme:



                        import React, Component from 'react' import 
                        StyleSheet,
                        View,
                        Text,
                        ScrollView,
                        Image,
                        TouchableHighlight from 'react-native'

                        import BoxShadow from 'react-native-shadow'

                        export default class VideoCell extends Component
                        render = () =>
                        const shadowOpt =
                        width:160,
                        height:170,
                        color:"#000",
                        border:2,
                        radius:3,
                        opacity:0.2,
                        x:0,
                        y:3,
                        style:marginVertical:5


                        return (
                        <BoxShadow setting=shadowOpt>
                        <TouchableHighlight style=
                        position:"relative",
                        width: 160,
                        height: 170,
                        backgroundColor: "#fff",
                        borderRadius:3,
                        // marginVertical:5,
                        overflow:"hidden">
                        …………………………
                        </TouchableHighlight>
                        </BoxShadow>
                        )








                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 15 at 8:01

























                        answered Jan 4 '17 at 6:40









                        FuzzyTree

                        26.1k22954




                        26.1k22954







                        • 2




                          Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. I tested it with React Native 0.52
                          – Guy
                          Jan 15 at 3:41










                        • Be careful when using elevation as it won't respect your settings for shadow, such as the color and offset.
                          – cseelus
                          Apr 5 at 17:55










                        • this lib, how to do if I don't know the specify width height of children. . . cuz it require.
                          – Leang Socheat
                          Oct 23 at 3:03












                        • 2




                          Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. I tested it with React Native 0.52
                          – Guy
                          Jan 15 at 3:41










                        • Be careful when using elevation as it won't respect your settings for shadow, such as the color and offset.
                          – cseelus
                          Apr 5 at 17:55










                        • this lib, how to do if I don't know the specify width height of children. . . cuz it require.
                          – Leang Socheat
                          Oct 23 at 3:03







                        2




                        2




                        Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. I tested it with React Native 0.52
                        – Guy
                        Jan 15 at 3:41




                        Adding css property elevation: 1 renders shadow in Android without installing any 3rd party library. I tested it with React Native 0.52
                        – Guy
                        Jan 15 at 3:41












                        Be careful when using elevation as it won't respect your settings for shadow, such as the color and offset.
                        – cseelus
                        Apr 5 at 17:55




                        Be careful when using elevation as it won't respect your settings for shadow, such as the color and offset.
                        – cseelus
                        Apr 5 at 17:55












                        this lib, how to do if I don't know the specify width height of children. . . cuz it require.
                        – Leang Socheat
                        Oct 23 at 3:03




                        this lib, how to do if I don't know the specify width height of children. . . cuz it require.
                        – Leang Socheat
                        Oct 23 at 3:03












                        up vote
                        65
                        down vote













                        Another solution without using a third-party library is using elevation.



                        Pulled from react-native documentation.
                        https://facebook.github.io/react-native/docs/view.html




                        (Android-only) Sets the elevation of a view, using Android's
                        underlying elevation API. This adds a drop shadow to the item and
                        affects z-order for overlapping views. Only supported on Android 5.0+,
                        has no effect on earlier versions.




                        elevation will go into the style property and it can be implemented like so.



                        <View style= elevation: 2 >
                        children
                        </View>


                        The higher the elevation, the bigger the shadow. Hope this helps!






                        share|improve this answer




















                        • why elevation attribute is written inside 2 braces?
                          – divine
                          Jun 24 '17 at 7:52






                        • 5




                          @divine the outer bracket is for JS interpolation, the inner is for an object
                          – Asaf David
                          Jun 25 '17 at 7:28






                        • 3




                          This only does a shadow on the bottom of a view, it doesn't allow you to do shadows on the other sides
                          – Erich
                          Aug 31 '17 at 18:41










                        • Correct, there are many things iOS handles better when using react-native and shadows are one of them.
                          – Ajackster
                          Aug 31 '17 at 20:25






                        • 2




                          Note: this only works in Android 5.0+
                          – Muhammad Riyaz
                          Sep 8 '17 at 10:31














                        up vote
                        65
                        down vote













                        Another solution without using a third-party library is using elevation.



                        Pulled from react-native documentation.
                        https://facebook.github.io/react-native/docs/view.html




                        (Android-only) Sets the elevation of a view, using Android's
                        underlying elevation API. This adds a drop shadow to the item and
                        affects z-order for overlapping views. Only supported on Android 5.0+,
                        has no effect on earlier versions.




                        elevation will go into the style property and it can be implemented like so.



                        <View style= elevation: 2 >
                        children
                        </View>


                        The higher the elevation, the bigger the shadow. Hope this helps!






                        share|improve this answer




















                        • why elevation attribute is written inside 2 braces?
                          – divine
                          Jun 24 '17 at 7:52






                        • 5




                          @divine the outer bracket is for JS interpolation, the inner is for an object
                          – Asaf David
                          Jun 25 '17 at 7:28






                        • 3




                          This only does a shadow on the bottom of a view, it doesn't allow you to do shadows on the other sides
                          – Erich
                          Aug 31 '17 at 18:41










                        • Correct, there are many things iOS handles better when using react-native and shadows are one of them.
                          – Ajackster
                          Aug 31 '17 at 20:25






                        • 2




                          Note: this only works in Android 5.0+
                          – Muhammad Riyaz
                          Sep 8 '17 at 10:31












                        up vote
                        65
                        down vote










                        up vote
                        65
                        down vote









                        Another solution without using a third-party library is using elevation.



                        Pulled from react-native documentation.
                        https://facebook.github.io/react-native/docs/view.html




                        (Android-only) Sets the elevation of a view, using Android's
                        underlying elevation API. This adds a drop shadow to the item and
                        affects z-order for overlapping views. Only supported on Android 5.0+,
                        has no effect on earlier versions.




                        elevation will go into the style property and it can be implemented like so.



                        <View style= elevation: 2 >
                        children
                        </View>


                        The higher the elevation, the bigger the shadow. Hope this helps!






                        share|improve this answer












                        Another solution without using a third-party library is using elevation.



                        Pulled from react-native documentation.
                        https://facebook.github.io/react-native/docs/view.html




                        (Android-only) Sets the elevation of a view, using Android's
                        underlying elevation API. This adds a drop shadow to the item and
                        affects z-order for overlapping views. Only supported on Android 5.0+,
                        has no effect on earlier versions.




                        elevation will go into the style property and it can be implemented like so.



                        <View style= elevation: 2 >
                        children
                        </View>


                        The higher the elevation, the bigger the shadow. Hope this helps!







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jan 6 '17 at 21:34









                        Ajackster

                        1,2781612




                        1,2781612











                        • why elevation attribute is written inside 2 braces?
                          – divine
                          Jun 24 '17 at 7:52






                        • 5




                          @divine the outer bracket is for JS interpolation, the inner is for an object
                          – Asaf David
                          Jun 25 '17 at 7:28






                        • 3




                          This only does a shadow on the bottom of a view, it doesn't allow you to do shadows on the other sides
                          – Erich
                          Aug 31 '17 at 18:41










                        • Correct, there are many things iOS handles better when using react-native and shadows are one of them.
                          – Ajackster
                          Aug 31 '17 at 20:25






                        • 2




                          Note: this only works in Android 5.0+
                          – Muhammad Riyaz
                          Sep 8 '17 at 10:31
















                        • why elevation attribute is written inside 2 braces?
                          – divine
                          Jun 24 '17 at 7:52






                        • 5




                          @divine the outer bracket is for JS interpolation, the inner is for an object
                          – Asaf David
                          Jun 25 '17 at 7:28






                        • 3




                          This only does a shadow on the bottom of a view, it doesn't allow you to do shadows on the other sides
                          – Erich
                          Aug 31 '17 at 18:41










                        • Correct, there are many things iOS handles better when using react-native and shadows are one of them.
                          – Ajackster
                          Aug 31 '17 at 20:25






                        • 2




                          Note: this only works in Android 5.0+
                          – Muhammad Riyaz
                          Sep 8 '17 at 10:31















                        why elevation attribute is written inside 2 braces?
                        – divine
                        Jun 24 '17 at 7:52




                        why elevation attribute is written inside 2 braces?
                        – divine
                        Jun 24 '17 at 7:52




                        5




                        5




                        @divine the outer bracket is for JS interpolation, the inner is for an object
                        – Asaf David
                        Jun 25 '17 at 7:28




                        @divine the outer bracket is for JS interpolation, the inner is for an object
                        – Asaf David
                        Jun 25 '17 at 7:28




                        3




                        3




                        This only does a shadow on the bottom of a view, it doesn't allow you to do shadows on the other sides
                        – Erich
                        Aug 31 '17 at 18:41




                        This only does a shadow on the bottom of a view, it doesn't allow you to do shadows on the other sides
                        – Erich
                        Aug 31 '17 at 18:41












                        Correct, there are many things iOS handles better when using react-native and shadows are one of them.
                        – Ajackster
                        Aug 31 '17 at 20:25




                        Correct, there are many things iOS handles better when using react-native and shadows are one of them.
                        – Ajackster
                        Aug 31 '17 at 20:25




                        2




                        2




                        Note: this only works in Android 5.0+
                        – Muhammad Riyaz
                        Sep 8 '17 at 10:31




                        Note: this only works in Android 5.0+
                        – Muhammad Riyaz
                        Sep 8 '17 at 10:31










                        up vote
                        29
                        down vote













                        You can try



                        //ios 
                        shadowOpacity: 0.3,
                        shadowRadius: 3,
                        shadowOffset:
                        height: 0,
                        width: 0
                        ,
                        //android
                        elevation: 1





                        share|improve this answer






















                        • Elevation does not create a large enough or configurable shadow for android - react-native-shadow seems like the best option
                          – evanjmg
                          Mar 6 at 12:02














                        up vote
                        29
                        down vote













                        You can try



                        //ios 
                        shadowOpacity: 0.3,
                        shadowRadius: 3,
                        shadowOffset:
                        height: 0,
                        width: 0
                        ,
                        //android
                        elevation: 1





                        share|improve this answer






















                        • Elevation does not create a large enough or configurable shadow for android - react-native-shadow seems like the best option
                          – evanjmg
                          Mar 6 at 12:02












                        up vote
                        29
                        down vote










                        up vote
                        29
                        down vote









                        You can try



                        //ios 
                        shadowOpacity: 0.3,
                        shadowRadius: 3,
                        shadowOffset:
                        height: 0,
                        width: 0
                        ,
                        //android
                        elevation: 1





                        share|improve this answer














                        You can try



                        //ios 
                        shadowOpacity: 0.3,
                        shadowRadius: 3,
                        shadowOffset:
                        height: 0,
                        width: 0
                        ,
                        //android
                        elevation: 1






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 15 at 7:46









                        Guy

                        1,30611526




                        1,30611526










                        answered Aug 2 '17 at 2:26









                        lam luu

                        42455




                        42455











                        • Elevation does not create a large enough or configurable shadow for android - react-native-shadow seems like the best option
                          – evanjmg
                          Mar 6 at 12:02
















                        • Elevation does not create a large enough or configurable shadow for android - react-native-shadow seems like the best option
                          – evanjmg
                          Mar 6 at 12:02















                        Elevation does not create a large enough or configurable shadow for android - react-native-shadow seems like the best option
                        – evanjmg
                        Mar 6 at 12:02




                        Elevation does not create a large enough or configurable shadow for android - react-native-shadow seems like the best option
                        – evanjmg
                        Mar 6 at 12:02










                        up vote
                        5
                        down vote













                        Just use 'elevation' property to get shadow in android. something like below



                        const Header = () => 
                        // const textStyle, viewStyle = styles;
                        return (
                        <View style=styles.viewStyle>
                        <Text style=styles.textStyle>Albums</Text>
                        </View>
                        )



                        const styles =
                        viewStyle:
                        backgroundColor:'#f8f8f8',
                        justifyContext:'center',
                        alignItems: 'center',
                        padding:16,
                        elevation: 2







                        share|improve this answer
























                          up vote
                          5
                          down vote













                          Just use 'elevation' property to get shadow in android. something like below



                          const Header = () => 
                          // const textStyle, viewStyle = styles;
                          return (
                          <View style=styles.viewStyle>
                          <Text style=styles.textStyle>Albums</Text>
                          </View>
                          )



                          const styles =
                          viewStyle:
                          backgroundColor:'#f8f8f8',
                          justifyContext:'center',
                          alignItems: 'center',
                          padding:16,
                          elevation: 2







                          share|improve this answer






















                            up vote
                            5
                            down vote










                            up vote
                            5
                            down vote









                            Just use 'elevation' property to get shadow in android. something like below



                            const Header = () => 
                            // const textStyle, viewStyle = styles;
                            return (
                            <View style=styles.viewStyle>
                            <Text style=styles.textStyle>Albums</Text>
                            </View>
                            )



                            const styles =
                            viewStyle:
                            backgroundColor:'#f8f8f8',
                            justifyContext:'center',
                            alignItems: 'center',
                            padding:16,
                            elevation: 2







                            share|improve this answer












                            Just use 'elevation' property to get shadow in android. something like below



                            const Header = () => 
                            // const textStyle, viewStyle = styles;
                            return (
                            <View style=styles.viewStyle>
                            <Text style=styles.textStyle>Albums</Text>
                            </View>
                            )



                            const styles =
                            viewStyle:
                            backgroundColor:'#f8f8f8',
                            justifyContext:'center',
                            alignItems: 'center',
                            padding:16,
                            elevation: 2








                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 11 '17 at 17:51









                            SameerShaik

                            201516




                            201516




















                                up vote
                                2
                                down vote













                                The following will help you to give each Platform the styling you want:



                                import Text, View, Platform from 'react-native';

                                ......
                                <View style=styles.viewClass></View>
                                ......


                                const styles =
                                viewClass:
                                justifyContent: 'center',
                                alignItems: 'center',
                                height: 60,
                                ...Platform.select(
                                ios:
                                shadowColor: '#000',
                                shadowOffset: width: 0, height: 2 ,
                                shadowOpacity: 0.2,
                                ,
                                android:
                                elevation: 1

                                ,
                                ),

                                ;





                                share|improve this answer
















                                • 2




                                  It's not needed to specify the platform since in iOS elevation property will be ignored
                                  – cody
                                  Jul 26 at 22:42










                                • @cody yes, you are right! but my example shows how to set styles for different platforms.
                                  – Mohammed Alawneh
                                  Jul 29 at 7:12















                                up vote
                                2
                                down vote













                                The following will help you to give each Platform the styling you want:



                                import Text, View, Platform from 'react-native';

                                ......
                                <View style=styles.viewClass></View>
                                ......


                                const styles =
                                viewClass:
                                justifyContent: 'center',
                                alignItems: 'center',
                                height: 60,
                                ...Platform.select(
                                ios:
                                shadowColor: '#000',
                                shadowOffset: width: 0, height: 2 ,
                                shadowOpacity: 0.2,
                                ,
                                android:
                                elevation: 1

                                ,
                                ),

                                ;





                                share|improve this answer
















                                • 2




                                  It's not needed to specify the platform since in iOS elevation property will be ignored
                                  – cody
                                  Jul 26 at 22:42










                                • @cody yes, you are right! but my example shows how to set styles for different platforms.
                                  – Mohammed Alawneh
                                  Jul 29 at 7:12













                                up vote
                                2
                                down vote










                                up vote
                                2
                                down vote









                                The following will help you to give each Platform the styling you want:



                                import Text, View, Platform from 'react-native';

                                ......
                                <View style=styles.viewClass></View>
                                ......


                                const styles =
                                viewClass:
                                justifyContent: 'center',
                                alignItems: 'center',
                                height: 60,
                                ...Platform.select(
                                ios:
                                shadowColor: '#000',
                                shadowOffset: width: 0, height: 2 ,
                                shadowOpacity: 0.2,
                                ,
                                android:
                                elevation: 1

                                ,
                                ),

                                ;





                                share|improve this answer












                                The following will help you to give each Platform the styling you want:



                                import Text, View, Platform from 'react-native';

                                ......
                                <View style=styles.viewClass></View>
                                ......


                                const styles =
                                viewClass:
                                justifyContent: 'center',
                                alignItems: 'center',
                                height: 60,
                                ...Platform.select(
                                ios:
                                shadowColor: '#000',
                                shadowOffset: width: 0, height: 2 ,
                                shadowOpacity: 0.2,
                                ,
                                android:
                                elevation: 1

                                ,
                                ),

                                ;






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 12 at 9:36









                                Mohammed Alawneh

                                5113




                                5113







                                • 2




                                  It's not needed to specify the platform since in iOS elevation property will be ignored
                                  – cody
                                  Jul 26 at 22:42










                                • @cody yes, you are right! but my example shows how to set styles for different platforms.
                                  – Mohammed Alawneh
                                  Jul 29 at 7:12













                                • 2




                                  It's not needed to specify the platform since in iOS elevation property will be ignored
                                  – cody
                                  Jul 26 at 22:42










                                • @cody yes, you are right! but my example shows how to set styles for different platforms.
                                  – Mohammed Alawneh
                                  Jul 29 at 7:12








                                2




                                2




                                It's not needed to specify the platform since in iOS elevation property will be ignored
                                – cody
                                Jul 26 at 22:42




                                It's not needed to specify the platform since in iOS elevation property will be ignored
                                – cody
                                Jul 26 at 22:42












                                @cody yes, you are right! but my example shows how to set styles for different platforms.
                                – Mohammed Alawneh
                                Jul 29 at 7:12





                                @cody yes, you are right! but my example shows how to set styles for different platforms.
                                – Mohammed Alawneh
                                Jul 29 at 7:12











                                up vote
                                1
                                down vote













                                for an android screen you can use this property elevation.



                                for example :



                                 HeaderView:
                                backgroundColor:'#F8F8F8',
                                justifyContent:'center',
                                alignItems:'center',
                                height:60,
                                paddingTop:15,

                                //Its for IOS
                                shadowColor: '#000',
                                shadowOffset: width: 0, height: 2 ,
                                shadowOpacity: 0.2,

                                // its for android
                                elevation: 5,
                                position:'relative',

                                ,





                                share|improve this answer


























                                  up vote
                                  1
                                  down vote













                                  for an android screen you can use this property elevation.



                                  for example :



                                   HeaderView:
                                  backgroundColor:'#F8F8F8',
                                  justifyContent:'center',
                                  alignItems:'center',
                                  height:60,
                                  paddingTop:15,

                                  //Its for IOS
                                  shadowColor: '#000',
                                  shadowOffset: width: 0, height: 2 ,
                                  shadowOpacity: 0.2,

                                  // its for android
                                  elevation: 5,
                                  position:'relative',

                                  ,





                                  share|improve this answer
























                                    up vote
                                    1
                                    down vote










                                    up vote
                                    1
                                    down vote









                                    for an android screen you can use this property elevation.



                                    for example :



                                     HeaderView:
                                    backgroundColor:'#F8F8F8',
                                    justifyContent:'center',
                                    alignItems:'center',
                                    height:60,
                                    paddingTop:15,

                                    //Its for IOS
                                    shadowColor: '#000',
                                    shadowOffset: width: 0, height: 2 ,
                                    shadowOpacity: 0.2,

                                    // its for android
                                    elevation: 5,
                                    position:'relative',

                                    ,





                                    share|improve this answer














                                    for an android screen you can use this property elevation.



                                    for example :



                                     HeaderView:
                                    backgroundColor:'#F8F8F8',
                                    justifyContent:'center',
                                    alignItems:'center',
                                    height:60,
                                    paddingTop:15,

                                    //Its for IOS
                                    shadowColor: '#000',
                                    shadowOffset: width: 0, height: 2 ,
                                    shadowOpacity: 0.2,

                                    // its for android
                                    elevation: 5,
                                    position:'relative',

                                    ,






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Aug 29 at 16:13









                                    Mahdi Bashirpour

                                    1,4952828




                                    1,4952828










                                    answered May 27 at 7:57









                                    Aras

                                    12216




                                    12216




















                                        up vote
                                        0
                                        down vote













                                        elevation still no work in Expo v30 && React-native v0.55.4.
                                        I have tried the all answers here.



                                        Also, don't try react-native-shadow - their shadow rendering is terrible.
                                        So, I am continuing the research.






                                        share|improve this answer
























                                          up vote
                                          0
                                          down vote













                                          elevation still no work in Expo v30 && React-native v0.55.4.
                                          I have tried the all answers here.



                                          Also, don't try react-native-shadow - their shadow rendering is terrible.
                                          So, I am continuing the research.






                                          share|improve this answer






















                                            up vote
                                            0
                                            down vote










                                            up vote
                                            0
                                            down vote









                                            elevation still no work in Expo v30 && React-native v0.55.4.
                                            I have tried the all answers here.



                                            Also, don't try react-native-shadow - their shadow rendering is terrible.
                                            So, I am continuing the research.






                                            share|improve this answer












                                            elevation still no work in Expo v30 && React-native v0.55.4.
                                            I have tried the all answers here.



                                            Also, don't try react-native-shadow - their shadow rendering is terrible.
                                            So, I am continuing the research.







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Sep 24 at 10:29









                                            Niklavr

                                            19113




                                            19113




















                                                up vote
                                                0
                                                down vote













                                                I have implemented CardView for react-native with elevation, that support android(All version) and iOS. Let me know is it help you or not. https://github.com/Kishanjvaghela/react-native-cardview



                                                import CardView from 'react-native-cardview'
                                                <CardView
                                                cardElevation=2
                                                cardMaxElevation=2
                                                cornerRadius=5>
                                                <Text>
                                                Elevation 0
                                                </Text>
                                                </CardView>


                                                enter image description here






                                                share|improve this answer
























                                                  up vote
                                                  0
                                                  down vote













                                                  I have implemented CardView for react-native with elevation, that support android(All version) and iOS. Let me know is it help you or not. https://github.com/Kishanjvaghela/react-native-cardview



                                                  import CardView from 'react-native-cardview'
                                                  <CardView
                                                  cardElevation=2
                                                  cardMaxElevation=2
                                                  cornerRadius=5>
                                                  <Text>
                                                  Elevation 0
                                                  </Text>
                                                  </CardView>


                                                  enter image description here






                                                  share|improve this answer






















                                                    up vote
                                                    0
                                                    down vote










                                                    up vote
                                                    0
                                                    down vote









                                                    I have implemented CardView for react-native with elevation, that support android(All version) and iOS. Let me know is it help you or not. https://github.com/Kishanjvaghela/react-native-cardview



                                                    import CardView from 'react-native-cardview'
                                                    <CardView
                                                    cardElevation=2
                                                    cardMaxElevation=2
                                                    cornerRadius=5>
                                                    <Text>
                                                    Elevation 0
                                                    </Text>
                                                    </CardView>


                                                    enter image description here






                                                    share|improve this answer












                                                    I have implemented CardView for react-native with elevation, that support android(All version) and iOS. Let me know is it help you or not. https://github.com/Kishanjvaghela/react-native-cardview



                                                    import CardView from 'react-native-cardview'
                                                    <CardView
                                                    cardElevation=2
                                                    cardMaxElevation=2
                                                    cornerRadius=5>
                                                    <Text>
                                                    Elevation 0
                                                    </Text>
                                                    </CardView>


                                                    enter image description here







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Sep 25 at 8:10









                                                    Kishan Vaghela

                                                    5,36122751




                                                    5,36122751




















                                                        up vote
                                                        0
                                                        down vote













                                                        In short, you can't do that in android, because if you see the docs about shadow only Support IOS see doc



                                                        The best option you can install 3rd party react-native-shadow






                                                        share|improve this answer
























                                                          up vote
                                                          0
                                                          down vote













                                                          In short, you can't do that in android, because if you see the docs about shadow only Support IOS see doc



                                                          The best option you can install 3rd party react-native-shadow






                                                          share|improve this answer






















                                                            up vote
                                                            0
                                                            down vote










                                                            up vote
                                                            0
                                                            down vote









                                                            In short, you can't do that in android, because if you see the docs about shadow only Support IOS see doc



                                                            The best option you can install 3rd party react-native-shadow






                                                            share|improve this answer












                                                            In short, you can't do that in android, because if you see the docs about shadow only Support IOS see doc



                                                            The best option you can install 3rd party react-native-shadow







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Nov 11 at 14:04









                                                            Muhammad Al Faris

                                                            11




                                                            11




















                                                                up vote
                                                                0
                                                                down vote













                                                                Set elevation: 3 and you should see the shadow in bottom of component without a 3rd party lib. At least in RN 0.57.4






                                                                share|improve this answer
























                                                                  up vote
                                                                  0
                                                                  down vote













                                                                  Set elevation: 3 and you should see the shadow in bottom of component without a 3rd party lib. At least in RN 0.57.4






                                                                  share|improve this answer






















                                                                    up vote
                                                                    0
                                                                    down vote










                                                                    up vote
                                                                    0
                                                                    down vote









                                                                    Set elevation: 3 and you should see the shadow in bottom of component without a 3rd party lib. At least in RN 0.57.4






                                                                    share|improve this answer












                                                                    Set elevation: 3 and you should see the shadow in bottom of component without a 3rd party lib. At least in RN 0.57.4







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Nov 12 at 9:55









                                                                    C-lio Garcia

                                                                    1056




                                                                    1056




















                                                                        up vote
                                                                        0
                                                                        down vote













                                                                        I had the same problem shadow/elevation not showing on Android with elevation:2. Then i noticed that the view element is fool width, so I added margin:2 to the view element and elevation properly appeared.



                                                                        Style:



                                                                         margin: 2,
                                                                        shadowColor: '#000',
                                                                        shadowOffset:
                                                                        width: 0,
                                                                        height: 1
                                                                        ,
                                                                        shadowOpacity: 0.2,
                                                                        shadowRadius: 1.41,
                                                                        elevation: 2


                                                                        Android:
                                                                        enter image description here



                                                                        iOS:
                                                                        enter image description here






                                                                        share|improve this answer
























                                                                          up vote
                                                                          0
                                                                          down vote













                                                                          I had the same problem shadow/elevation not showing on Android with elevation:2. Then i noticed that the view element is fool width, so I added margin:2 to the view element and elevation properly appeared.



                                                                          Style:



                                                                           margin: 2,
                                                                          shadowColor: '#000',
                                                                          shadowOffset:
                                                                          width: 0,
                                                                          height: 1
                                                                          ,
                                                                          shadowOpacity: 0.2,
                                                                          shadowRadius: 1.41,
                                                                          elevation: 2


                                                                          Android:
                                                                          enter image description here



                                                                          iOS:
                                                                          enter image description here






                                                                          share|improve this answer






















                                                                            up vote
                                                                            0
                                                                            down vote










                                                                            up vote
                                                                            0
                                                                            down vote









                                                                            I had the same problem shadow/elevation not showing on Android with elevation:2. Then i noticed that the view element is fool width, so I added margin:2 to the view element and elevation properly appeared.



                                                                            Style:



                                                                             margin: 2,
                                                                            shadowColor: '#000',
                                                                            shadowOffset:
                                                                            width: 0,
                                                                            height: 1
                                                                            ,
                                                                            shadowOpacity: 0.2,
                                                                            shadowRadius: 1.41,
                                                                            elevation: 2


                                                                            Android:
                                                                            enter image description here



                                                                            iOS:
                                                                            enter image description here






                                                                            share|improve this answer












                                                                            I had the same problem shadow/elevation not showing on Android with elevation:2. Then i noticed that the view element is fool width, so I added margin:2 to the view element and elevation properly appeared.



                                                                            Style:



                                                                             margin: 2,
                                                                            shadowColor: '#000',
                                                                            shadowOffset:
                                                                            width: 0,
                                                                            height: 1
                                                                            ,
                                                                            shadowOpacity: 0.2,
                                                                            shadowRadius: 1.41,
                                                                            elevation: 2


                                                                            Android:
                                                                            enter image description here



                                                                            iOS:
                                                                            enter image description here







                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered Nov 25 at 13:36









                                                                            Kristijan Tomić

                                                                            414




                                                                            414



























                                                                                draft saved

                                                                                draft discarded
















































                                                                                Thanks for contributing an answer to Stack Overflow!


                                                                                • Please be sure to answer the question. Provide details and share your research!

                                                                                But avoid


                                                                                • Asking for help, clarification, or responding to other answers.

                                                                                • Making statements based on opinion; back them up with references or personal experience.

                                                                                To learn more, see our tips on writing great answers.





                                                                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                Please pay close attention to the following guidance:


                                                                                • Please be sure to answer the question. Provide details and share your research!

                                                                                But avoid


                                                                                • Asking for help, clarification, or responding to other answers.

                                                                                • Making statements based on opinion; back them up with references or personal experience.

                                                                                To learn more, see our tips on writing great answers.




                                                                                draft saved


                                                                                draft discarded














                                                                                StackExchange.ready(
                                                                                function ()
                                                                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41320131%2fhow-to-set-shadows-in-react-native-for-android%23new-answer', 'question_page');

                                                                                );

                                                                                Post as a guest















                                                                                Required, but never shown





















































                                                                                Required, but never shown














                                                                                Required, but never shown












                                                                                Required, but never shown







                                                                                Required, but never shown

































                                                                                Required, but never shown














                                                                                Required, but never shown












                                                                                Required, but never shown







                                                                                Required, but never shown







                                                                                這個網誌中的熱門文章

                                                                                What does pagestruct do in Eviews?

                                                                                Dutch intervention in Lombok and Karangasem

                                                                                Channel Islands