7

I am a beginner in React Native and I just want to write my first line of code with it. I made a button and started wondering how can I change the colour and other properties of the text in the button. <Button title="Click Me"></Button>

I was also wondering if there are some good packages that are recommended for beginners. Thanks for the help.

4 Answers 4

11

You can use a Button from react-native like this and can also pass the color prop.

Button
  onPress={onPressLearnMore}
  title="Click Me"
  color="#841584"
/>

For complex and custom buttons you can create it by your own styles using Touchables which are given by react-native you don't have to use any third-party libraries for that.

Example:

    <TouchableOpacity style={{ here you can specify custom styles for button container }} onPress={gotoDashboard}>
        <Text style={{here you can specify text styles}}>Button Text Here</Text>
  // You can add there as many components according to your designs.
      </TouchableOpacity>
Sign up to request clarification or add additional context in comments.

3 Comments

The first code doesn't change the text colour.
the button component does not have the option to change the text color. The color property just changes the overall background color of the Button. You have to use Touchable for custom buttons. Try the second example. I hope that will workout
@Akshay Bhanderi is correct in their answer that your first solution sets the text color in ios, but it sets the background color in andriod, making TouchableOpacity a good solution
3

You should use titleStyle like this:

<Button
  titleStyle={{
     color: '#00BAD4',
     fontSize: 30,
     fontStyle: 'italic',
  }}
  title="Title"
  buttonStyle={{
     backgroundColor: '#FFF',
     borderRadius: 4,
     margin: 5,
  }}
/>

Btw here's more useful information about buttons: https://reactnativeelements.com/docs/components/button

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
1

So, the color prop of react native Button behaves differently in IOS and Android as per official docs It affects the background color if it's Android while the font color if it's IOS. So, you have to specify styles as per that.

One good alternative can be TouchableOpacity.

Comments

0

To Make Button Text Color in React Native Just add Following Line

<Button color="#2ECC71" title='Click Me'/>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.