有没有可能在Facebook Android SDK3中更改Facebookloginbutton图像?

Facebook的Android SDK有一个com.facebook.widget.LoginButton

我想把我自己的图像的loginbutton。 可能吗 ?

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

我结束了重写文本为空string,然后定义button的setBackgroundResource我的形象(不需要dynamiclogin/注销文本function)

 <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="" /> 

在代码中,我定义了背景资源:

 final LoginButton button = (LoginButton) findViewById(R.id.login_button); button.setBackgroundResource(R.drawable.facebook); 

一种解决方法,但我更喜欢这改变Facebook SDK代码(虽然它也是非常简单的),并担心更新每次我更新他们的版本。

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

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

其他方式

 loginButton = (LoginButton) findViewById(R.id.fb_login_button); loginButton.setVisibility(View.GONE); ImageView ivFbCustomButton = (ImageView) findViewById(R.id.iv_fb_custom_button); ivFbCustomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { com.facebook.login.widget.LoginButton btn = new com.facebook.login.widget.LoginButton(FacebookActivity.this); btn.performClick(); } }); 

注意:

您必须在XML文件中编写两个button的代码。 一个是默认的Facebookbutton(我们在第一步隐藏它)。 第二个是自定义button