Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Button Font Size on React Native [closed]

I'm trying to change Button font-size on my react native app, but I got an error. Does anyone know how to properly do it? Thank you.

like image 410
webprogramming13 Avatar asked Apr 27 '18 15:04

webprogramming13


People also ask

How do I change the text on a button click in React Native?

To change a button's text on click in React:Track the text of the button in a state variable. Set the onClick prop on the button element. When the button gets clicked, update the state variable.

How do I fix text size in React Native?

You need to use fontSize attribute/property of stylesheet design, in order to set text font size in your Text component. Set Fontsize in react native application : Using below CSS properties you can set font size in your react native application.

How do I customize my React Native button?

import { View, Button, StyleSheet, TouchableOpacity, Text } from "react-native"; To create custom buttons, you need to customize the <TouchableOpacity /> component and include the <Text /> component inside of it to display the button text.


5 Answers

You can use react-native-elements with titleStyle props.

import {Input, Button} from 'react-native-elements';

<Button
   onPress={this.addPicture}
   titleStyle={{
       color: "white",
       fontSize: 16,
   }}
   buttonStyle={{
       backgroundColor: "white",
       borderRadius: 60,
       flex: 1,
       height: 30,
       width: 30,  
   }}

   title="+"
/>
like image 87
loic queruel Avatar answered Sep 21 '22 03:09

loic queruel


I have a feeling you're not using a Text element inside of your Touchable:

import React from 'react';
import { TouchableWithoutFeedback, Text } from 'react-native';

export default function ComponentName() {
  return (
    <TouchableWithoutFeedback>
      <Text style={{ fontSize: 24 }}>Button Text</Text>
    </TouchableWithoutFeedback>
  );
}
like image 41
AryanJ-NYC Avatar answered Sep 24 '22 03:09

AryanJ-NYC


Unfortunately, according to the documentation (https://reactnative.dev/docs/button) you can't change a font-size of a button. The only style prop you can change is color.

<Button
  onPress={onPressLearnMore}
  title="Learn More"
  color="#841584"
  accessibilityLabel="Learn more about this purple button"
/>
like image 21
Oleh Chemerskyi Avatar answered Sep 23 '22 03:09

Oleh Chemerskyi


Here is my solution to easily style buttons using TouchableOpacity with Text:

import React, { Component } from 'react';
import { View, StyleSheet, TouchableOpacity, Text } from "react-native";

export default class CustomButton extends Component {
  render(){
    return (
      <View style={styles.container}>

        /* Custom Button */
        <TouchableOpacity
          style={styles.customBtnBG}
          onPress={() => {}} 
        >
          <Text style={styles.customBtnText}>Button</Text>
        </TouchableOpacity>

      </View>
    )
  }
}


const styles = StyleSheet.create({
  container: {
    flex: 1,
        justifyContent: "center",
    alignItems: "center"
  },

  /* Here style the text of your button */
    customBtnText: {
        fontSize: 40,
        fontWeight: '400',
        color: "#fff",
    },

  /* Here style the background of your button */
    customBtnBG: {
    backgroundColor: "#007aff",
    paddingHorizontal: 30,
    paddingVertical: 5,
    borderRadius: 30
    }
});
like image 24
JulienRioux Avatar answered Sep 23 '22 03:09

JulienRioux


Use this library https://github.com/APSL/react-native-button instead of Button component in react native.

<View>
  <Button
    style={{
      backgroundColor: "#FE434C",
      borderColor: "transparent",
      borderRadius: 20,
      width: 250
    }}
    textStyle={{ color: "#FFFFFF", fontSize: 20 }}
  >
    Hello
  </Button>
</View>
like image 43
SDushan Avatar answered Sep 23 '22 03:09

SDushan