简体   繁体   中英

Make responsive button in react native

I want to make button in react native with dynamic width. I just want to supply text in button component it create button according to text width.

<View style={{justifyContent: 'center', alignItems: 'center'}}>
    <TouchableHighlight style={{backgroundColor:'red', paddingTop:10, paddingLeft:20, paddingRight:20, paddingBottom:10}}>
        <Text style={{color:'white', fontWeight:'bold'}}>BUTTON 2</Text>
    </TouchableHighlight>
</View>

To accomplish this, use padding. I've set up an example here .

<TouchableHighlight style={{backgroundColor:'red', paddingTop:10, paddingLeft:20, paddingRight:20, paddingBottom:10}}>
    <Text style={{color:'white', fontWeight:'bold'}}>BUTTON 2</Text>
</TouchableHighlight>

https://rnplay.org/apps/Hwinnw

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM