I am learning React Native programming for Android mobile apps. I am making a screen where I need to set height of button.
I have added button
in view
and set the height of using style however there is no change on button height.
/**
* LoginComponent of Myntra
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react";
import { AppRegistry, Text, View, Button, TextInput } from "react-native";
class LoginComponent extends Component {
render() {
return (
<View style={{ flex: 1, flexDirection: "column", margin: 10 }}>
<TextInput
style={{
height: 40,
borderColor: "gray",
borderWidth: 0.5
}}
placeholder="Email address"
underlineColorAndroid="transparent"
/>
<TextInput
style={{
height: 40,
borderColor: "gray",
borderWidth: 0.5
}}
placeholder="Password"
secureTextEntry={true}
underlineColorAndroid="transparent"
/>
<View style={{ height: 100, marginTop: 10 }}>
<Button title="LOG IN" color="#2E8B57" />
</View>
</View>
);
}
}
AppRegistry.registerComponent("Myntra", () => LoginComponent);
Can anyone help me to set the height of button according to my requirement?
Best solution is to use minHeight or maxHeight instead of using Height const. Show activity on this post. It often happens that we want to change the dimensions of the button, which by default is extended to the entire width of the parent element.
To resize a React Material UI button, we set can the style prop of the Button to an object that sets the dimensions of the button. We add a button by adding the Button component. And we set the style prop of the button to an object that has the maxWidth , maxHeight , minWidth and minHeight properties.
we need to specificity the color attribute and their corresponding color in button tag, In order to set the button color in react native application. Specify the button width and height in view layout instead of button. Mention the color attribute in button component, that helps to set the button color.
We will use Dimensions component of react-native to get the Height and Width of the Device. In mobile app development, we have to support different screens sizes. Especially if you are working on an App where responsiveness matters a lot then you need to keep track of Device Height and Width.
Welcome to Infinitbility. Sometimes, we need to create on bottom fixed button so users can press button at any level of scrolling they don’t need to go end of the screen to submit a button. So, Today we will see how we can create bottom fixed button in react native.
Flat Button: This has a style of no background color. To create a flat button in react, set the CSS class to e-flat. 3. Outline Button: This type of button contains a border with a transparent background.
Getting started with React Native will help you to know more about the way you can make a React Native project. We are going to use react-native init to make our React Native App. Assuming that you have node installed, you can use npm to install the react-native-cli command line utility.
This component has limited options, so you can't resize it to a fixed height
.
I recommend you to use the TouchableOpacity
component to build your own button, with own properties
and styles
.
You can easily style it like this:
<TouchableOpacity style={{ height: 100, marginTop: 10 }}>
<Text>My button</Text>
</TouchableOpacity>
You can set the button width as per the mentioned width easily by using following method :
<View style={[{ width: "90%", margin: 10, backgroundColor: "red" }]}>
<Button
onPress={this.buttonClickListener}
title="Button Three"
color="#FF3D00"
/>
</View>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With