React Native: Struggling with Button Styling

I am relatively new to React Native, although I have experience with React in my professional work. I'm finding that applying styles to components in React Native is a bit different than what I'm used to.

Specifically, I am struggling to apply styles to a button component.

Below is the code snippet I am currently working with:

<Button
  title="LET'S GET STARTED"

  onPress={() => {
    console.log('You tapped the Decrypt button!');
  }}
  buttonStyle={{
    backgroundColor: "#0A6ABB",
    width: 300,
    height: 45,
    borderColor: "#FFFFFF",
    borderWidth: 2,
    borderRadius: 5
  }}
  containerStyle={{ marginTop: 50 }}
/>

Despite trying various methods, I can't seem to get the styles to apply to my button as intended.

Here is a screenshot showing how it currently appears: https://i.stack.imgur.com/MEhpI.png

The text on the "Let's get started" button remains default blue, regardless of my styling attempts. Can someone please advise me on how to resolve this issue? Your help would be greatly appreciated.

Answer №1

Have you imported the Button component from react-native? If so, styling it may not be possible according to their documentation. The supported props listed do not include buttonStyle. You could consider using alternatives such as the Button component from react-native-elements or NativeBase

  • onPress
  • title
  • accessibilityLabel
  • color
  • disabled
  • testID
  • hasTVPreferredFocus

Answer №2

Button has some limitations in react native, but you can use TouchableOpacity for more flexibility. Check out the documentation here.

Here's an example of using TouchableOpacity:

render () {
  return (
    <TouchableOpacity
      style={styles.button}
      onPress={this.onPress} >
      <Text> LETS GET STARTED </Text>
    </TouchableOpacity>
  )
}
const styles = StyleSheet.create({
  button: {
    alignItems: 'center',
    backgroundColor: '#DDDDDD',
    padding: 10
  },
});

There are other types of "buttons" available as well, like TouchableHighlight and TouchableWithoutFeedback.

Answer №3

To implement a touchable button, utilize the TouchableOpacity component.


import { StyleSheet, TouchableOpacity, Text }

render() {
      return (
        <TouchableOpacity
          style={styles.button}
          onPress={() => { console.log('You tapped the Decrypt button!'); }}
        >
          <Text> LET'S GET STARTED </Text>
        </TouchableOpacity>
      )
    }

const styles = StyleSheet.create({
      button: {
        alignItems: 'center',
        backgroundColor: "#0A6ABB",
        width: 300,
        height: 45,
        borderColor: "#FFFFFF",
        borderWidth: 2,
        borderRadius: 5,
        marginTop: 50
      },
    });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generating a new object from a TypeScript class using JavaScript

Currently, I am facing an issue while attempting to call a JavaScript class from TypeScript as the compiler (VS) seems to be having some trouble. The particular class in question is InfoBox, but unfortunately, I have not been able to locate a TypeScript d ...

How can I remove the div container every time the submit button is clicked?

I am currently working on a form that is capturing values as shown below. <form role="form" id="calculate"> <div class="form-group"> <select class="form-control" id="paper"> < ...

What is the best way to store textarea information into a session using the jQuery AJAX post method in Codeigniter?

I am having trouble saving the text from a textarea to the Controller session using jQuery AJAX post method in Codeigniter Smarty. I am unable to save the data to the session. Can someone please provide me with guidance and a detailed example of how to ach ...

The dependency tree could not be resolved by ERESOLVE during the installation of the npm package react-alert

Encountered an error while trying to install react-alert through npm. The issue is with resolving the dependency tree, causing a conflict between different versions of React. To resolve this, you can try fixing the upstream dependency conflict, or reattem ...

Enabling ng-disabled within an ng-repeat loop

I'm facing an issue with a form that is nested inside an ng-repeat directive. The form should only be enabled if a specific field (in this case a select dropdown) is selected, but for some reason, it's not working as expected. Can anyone provide ...

Loading a different webpage seamlessly without having to reload the current one

Here is a snippet of my code in okay.html: {% extends "sch/base.html" %} {% load staticfiles %} {% block content %} <div class="row" id="ada"> <form action="" method="post> {% csrf_token %} <div align="center" class="cont ...

Containerize a ReactJS application and a Node/Express application integrated with AWS services

I have a frontend application built with ReactJS and for the backend, I am using Node/Express APIs. After developing the node/express app locally, I deploy the entire application on AWS Lambda function. I also utilize other AWS services such as HTTP API g ...

Showing a collection of articles on a webpage using Nuxt/content - Step by step guide

I have implemented the nuxt/content module to establish a documentation website. In a recent post on the Nuxt blog, they demonstrated displaying content in a separate index.vue page and post details on the _slug.vue page. My goal is to present a list of ...

Tips for moving a polygon while dragging a marker within its boundaries

Currently, I have a map displaying polygons and markers, accompanied by a sidebar featuring tool buttons (similar to the setup showcased in this demo: ). Each marker on my map is connected to the respective polygon stored in my database. When I utilize the ...

What is the best way to showcase my customized license plate on the following page?

I need help with incorporating my number plate builder into a website. I have utilized JQUERY and JAVASCRIPT for the styling aspect, but now I want to display the designed plate on the next page. Can someone guide me on how to achieve this using PHP, JQUER ...

Creating a dynamic image slider that smoothly glides across a webpage

I've been working on a carousel (image slider) for my website and I need some help. Specifically, I want to reposition the entire slider slightly to the left on the webpage. You can see the slider in action on this site: and I also created a jsfiddle ...

Ways to retrieve text like innerText that functions across all web browsers

I need to retrieve the text from a Twitter Follow button, like on https://twitter.com/Google/followers Using document.getElementsByClassName("user-actions-follow-button js-follow-btn follow-button")[0].innerText correctly displays the text as: Follow ...

When a number is added to an array containing strings, the result is a string rather than a number

Currently, I am attempting to change my array key value from a string to a number within my JSON object: form["price"] == "23" console.log(typeof form["price"]) // string form["price"] == Number(parseFloat(this.formObject[field.fieldName])) The issue aris ...

Utilize a Web Api controller to authenticate and verify the data input in

Currently, I am working on a web API application that includes the following form: <form id="editForm"> <input id="editid" type="hidden" name="id" /> <p><label>Numéro cnss </label&g ...

I would like for my element to increase and decrease in size while rotating when the button is clicked

I am trying to create an element that changes its size while spinning when a button is clicked. It seems to be working fine on hover, but not onclick. Here is the code I have: <div class="rec">Rec</div> <button id="button&quo ...

Is a preloader needed in a Vue.js app?

I'm currently exploring the world of Vue.js and could use some advice. When making a GET request using the axios package, I would like to display a preloader for the entire page until all the data has been loaded. While I know this is a common task i ...

Creating responsive tabs that transition into a drop-down menu for mobile devices is a useful feature for

I am looking to create a responsive tab design that drops down like the example shown below: Desktop/Large Screen View https://i.stack.imgur.com/hiCYz.png Mobile View https://i.stack.imgur.com/gRxLv.png I have written some code for this, but I am unsure ...

creating a mixin for a box-shadow value of none in LESS CSS

I'm encountering a challenge with implementing the box-shadow mixin in LESS css. Here's the mixin for box-shadow: .boxShadow (@x, @y, @blur, @spread: 0, @alpha) { -webkit-box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha); -moz-box-s ...

Switch up the color of the following-mouse-div in real-time to perfectly complement the color that lies underneath it

I am trying to create a div that changes color based on the complementary color of whatever is underneath the mouse pointer. I want it to follow the mouse and dynamically adjust its color. This functionality is similar to what Gpick does: https://www.you ...

Please ensure that the menu is included within the HTML file

How can I include a menu from menu.html into index.html? The content of menu.html is: <li><a href="home.html">Home</a></li> <li><a href="news.html">News</a></li> In index.html, the code is: <!docty ...