Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native Button style not work

Import_this

import {AppRegistry, Text, View, Button, StyleSheet} from 'react-native'; 

This my React Button code But style not working Hare ...

<Button   onPress={this.onPress.bind(this)}    title={"Go Back"}   style={{color: 'red', marginTop: 10, padding: 10}} /> 

Also I was try by this code

<Button         containerStyle={{padding:10, height:45, overflow:'hidden',         borderRadius:4, backgroundColor: 'white'}}        style={{fontSize: 20, color: 'green'}}         onPress={this.onPress.bind(this)} title={"Go Back"}       > Press me! </Button> 

Update Question:

Also I was try by This way..

<Button     onPress={this.onPress.bind(this)}     title={"Go Back"}     style={styles.buttonStyle} >ku ka</Button> 

Style

const styles = StyleSheet.create({     buttonStyle: {         color: 'red',         marginTop: 20,         padding: 20,         backgroundColor: 'green'     } }); 

But No out put: Screenshot of my phone:- Screenshot  of my phone:-

like image 926
MD Ashik Avatar asked Apr 24 '17 10:04

MD Ashik


People also ask

How do I apply a style in React Native button?

The closest we can get to styling a <Button /> exported from React Native is with the color prop. Below is an example of two buttons on Android, iOS, and the web. The first button is the default <Button /> and the second is another default <Button /> with its color prop set to `"red".

How do you change the style of a button in react?

To change the style of an element 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 new styles based on the state variable.

How do I change my style onPress React Native?

To change button style on press in React Native, we can wrap our button with the TouchableHighlight component. to define the touchProps object that we use to set the props of TouchableHighlight . We set onHideUnderlay to a function that runs when the underlay is hidden.

How do you color a button in React Native?

To change background color of React Native button, we can set the color prop for Android and we set the backgroundColor for iOS. to add <Button title="Login Android" color="#1E6738" /> add a button with the background color set to #1E6738 for Android.


1 Answers

The React Native Button is very limited in what you can do, see; Button

It does not have a style prop, and you don't set text the "web-way" like <Button>txt</Button> but via the title property <Button title="txt" />

If you want to have more control over the appearance you should use one of the TouchableXXXX' components like TouchableOpacity They are really easy to use :-)

like image 88
Plaul Avatar answered Sep 19 '22 09:09

Plaul