Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I specify a default color for a react-native-elements button?

Tags:

react-native

Right now I am using the react-native-elements component library for my app. Specifically I am using their Button component, which has a default color of grey applied to it.

enter image description here

How can I set a custom default color for these buttons without having to pass in style props every time?

Is there a simple function/method I can call, or do I have to look at creating a custom component to wrap it? I would prefer the former.

like image 674
Tope Avatar asked Feb 09 '17 01:02

Tope


People also ask

How do I change the color of my react button?

To change background color on click in React:Set the onClick prop on the element. When the element is clicked, set the active state. Use a ternary operator to conditionally set the background color based on the state variable.

How do I customize my react native button?

To create custom buttons, you need to customize the <TouchableOpacity /> component and include the <Text /> component inside of it to display the button text. const AppButton = ({ onPress, title }) => ( <TouchableOpacity onPress={onPress} style={styles. appButtonContainer}> <Text style={styles.

How do you make a button red in react?

You should use the hex code backgroundColor="#FF0000" instead of color="red" .


1 Answers

I know this is an old question, but since i found this post, i will leave this answer here for others to see.

react-native-elements supports theming since Oct 2018. As per the documentation you can use a theme provider in your RN application and override the library's default colors by doing something like this:

import { ThemeProvider } from 'react-native-elements';

const theme = {
  colors: {
    primary: 'pink',
  }
}

....
....

render(){
  ...
  return(
      <ThemeProvider theme={theme} >
         <App/>
      </ThemeProvider>
   )
}

The above example will change the primary color for all your components. By applying the same logic, you can change the background color only for button elements. You can also use theming for other customizations, like default component properties etc. For more information, check out the docs

like image 104
Vely Avatar answered Sep 18 '22 15:09

Vely