如何在React Native(Android)的Facebook登录按钮中居中文本?

问题描述 投票:4回答:1

我在我的React-Native应用程序中使用Facebook SDK(通过react-native-fbsdk)登录按钮。

按钮文本Continue with Facebook在iOS中垂直居中,但在Android(7.0)中偏离中心。

我唯一的选择是制作我自己的手动调用LoginManager的自定义按钮,还是有办法使用样式对齐文本(我试过alignItems和justifyContent)?看来我必须做基于this SO question的前者。

这是我现在的代码:

<LoginButton
   scope={'public_profile email'}
   style={{
       width: 220,
       height: 40
   }}
   onLoginFinished={this._facebookLogin}
   onLogoutFinished={() => console.log('logout.')}
/>

Photo of misaligned text

android reactjs react-native fbsdk
1个回答
1
投票

您可以将按钮包装到容器中

<View style={{
  width: 220, // whatever you want
  height: 50, // whatever you want
  justifyContent: 'center', // center the button
  backgroundColor: '#4267B2', // the same as the actual button
  paddingHorizontal: 10 // optionally add some horizontal padding for better looking
}}>
  <LoginButton
    scope={'public_profile email'}
    style={{
       flex: 1, // fill the container
       maxHeight: 30 // the default height
   }}
   onLoginFinished={this._facebookLogin}
   onLogoutFinished={() => console.log('logout.')}
  />
</View>

结果

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.