Android Google 登录按钮和 Facebook sdk 4+ 按钮布局

2024-02-18

我正在开发一个使用的应用程序google https://developers.google.com/+/branding-guidelines#sign-in-button and facebook https://developers.facebook.com/集成...我想修复这些按钮的高度和宽度...并且我想手动设置按钮文本...

到目前为止我已经尝试过

<com.facebook.login.widget.LoginButton
       xmlns:fb="http://schemas.android.com/apk/res-auto"
       android:id="@+id/connectWithFbButton"  
       android:layout_width="match_parent"
       android:layout_height="50dp"
       android:layout_marginLeft="10dp"
       android:layout_marginRight="10dp"
       android:text="@string/fbloginText"
       android:layout_marginTop="30dp"
/>

<com.google.android.gms.common.SignInButton
        android:id="@+id/signin"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:text="@string/googleloginText" 
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"/>

虽然我尝试过这样的事情

    fb:login_text="Login"
    fb:logout_text="Logout"

         or 

    facebook:login_text="Login" 

但我收到错误::=>在包“com.test.b2c”中找不到属性“login_text”的资源标识符

或通过编码

    loginButton = (LoginButton) findViewById(R.id.connectWithFbButton);
     loginButton.setText("Login");

现在我的布局看起来像这样

我还想设置这个按钮的高度和宽度.... 帮助我的朋友......提前致谢

UPDATE

我在设置宽度方面没有直接问题,我真正关心的是图片中显示的不一致的高度。我需要找到更好的方法来使这些按钮的高度相等并将文本设置为这些按钮。


如果我们想更改 Facebook 登录的自定义文本..

转到 Facebook 库项目并转到 string.xml

你会发现这样的东西

  <string name="com_facebook_loginview_log_in_button_long">Log in with facebook </string>

将其替换为您的自定义文本

不过,如果您想更改 Google Plus 的自定义文本,您可以

From OnCreate称之为

 setGooglePlusButtonText(signinButton,"your custom text");

//Google Plus的文本更改方法

protected void setGooglePlusButtonText(SignInButton signInButton,
    String buttonText) {
    for (int i = 0; i < signInButton.getChildCount(); i++) {
    View v = signInButton.getChildAt(i);

       if (v instanceof TextView) {
           TextView tv = (TextView) v;
           tv.setTextSize(15);
           tv.setTypeface(null, Typeface.NORMAL);
           tv.setText(buttonText);
         return;
         }
      }
}

对于 facebook 的高度不一致,我添加了填充Facebook 按钮 XML

android:paddingTop="20dp"
android:paddingBottom="20dp"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Google 登录按钮和 Facebook sdk 4+ 按钮布局 的相关文章

随机推荐