in html I can achieve this by
<span style="background-color:red">ketan</span>
but in react native how to implement this so that color will be applied to the text only.
in html I can achieve this by
<span style="background-color:red">ketan</span>
but in react native how to implement this so that color will be applied to the text only.
If you want the background color to only encompass the text, you can use this:
<Text style={{backgroundColor: 'blue', alignSelf: 'flex-start'}}>
Ketan
</Text>
And just change alignSelf as needed, you need to set this property if you dont want the text to take the whole width of the container
In react native you can directly use "Text" component and apply "backgroundColor" style to it as follows:
<Text>
<Text style={{ backgroundColor: "red", color: "white" }}>color
</Text>
</Text>
In react native you have Text
component to display text.
To set color of Text
, you can use color
property of it
<Text style={{color:'#ff0000'}}>Your Text</Text>
And for background color of that text, you can use View
and than set backgroundColor
of that View
you can't on IOS. set backgroundColor for extra View
<View style={{backgroundColor: 'red',flex:1}}><Text >ketan
</Text></View>
flex:1
or flex:0
–
Capricorn <Text> <Text style={{ backgroundColor: "red", color: "white" }}>color</Text> </Text>
–
Pedo try this one:
<Text style={{backgroundColor:'red', color:'white'}}>{'Message'}</Text>
import { Text } from 'react-native';
<Text style={{backgroundColor: 'green'}}>
Ketan
</Text>
In order to put text in ReactNative, you need Text
component. And you can apply backgroundColor
onto style
property.
Here's a snack as a demo to show usage and as playground for you to play around
© 2022 - 2024 — McMap. All rights reserved.