是否有可能在Facebook Android SDK3中更改Facebook登录按钮图像?

Mic*_*ael 34 android facebook-android-sdk

Facebook Android sdk有一个 com.facebook.widget.LoginButton

我想将自己的图像放入"登录"按钮.可能吗 ?

到目前为止,我已经尝试添加android:src="@drawable/facebook"布局文件作为按钮元素的属性,没有运气

Mic*_*ael 78

我最终将文本覆盖为空字符串,然后将setBackgroundResource按钮定义为我的图像(不需要动态登录/注销文本功能)

<com.facebook.widget.LoginButton
        xmlns:fb="http://schemas.android.com/apk/res-auto"
        android:id="@+id/login_button"
        android:layout_width="249dp"
        android:layout_height="45dp"
        android:layout_above="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="30dp"
        android:layout_marginTop="30dp"
        android:contentDescription="@string/login_desc"
        android:scaleType="centerInside"
        fb:login_text=""
        fb:logout_text="" />
Run Code Online (Sandbox Code Playgroud)

在代码中我定义了后台资源:

final LoginButton button = (LoginButton) findViewById(R.id.login_button);
button.setBackgroundResource(R.drawable.facebook);
Run Code Online (Sandbox Code Playgroud)

有点解决方法,但我更喜欢改变Facebook SDK代码(虽然它也非常直接),并担心每次更新其版本时都要更新.

  • add button.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0); 删除Facebook的'f'图标. (25认同)
  • Facebook sdk是开源的.检查其res/values/attrs.xml (3认同)
  • 它仍然显示Facebook的"f"图标,如何删除? (3认同)
  • 在android-studio中新更新的facebook sdk-我没有找到资源错误fb:login_text =""fb:logout_text =""构建时间相同的代码但是高于2错误 (3认同)
  • 要更改文本facebook:com_facebook_login_text ="New text"https://github.com/facebook/facebook-android-sdk/blob/master/facebook/res/values/attrs.xml (2认同)

小智 10

是的,如果你想更改文本和图像,然后写下面的代码.

authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setBackgroundResource(R.drawable.icon);
authButton.setText("Login");
authButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);`
Run Code Online (Sandbox Code Playgroud)