Gop*_*ath 13 android android-layout facebook-android-sdk
Facebook Sdk for Android不接受从XML传递的login_text和logout_text值.它只是忽略它.地球上没有使用此按钮自定义的文档/示例.
<com.facebook.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:id="@+id/connectWithFbButton"
style="@style/com_facebook_loginview_default_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text="@string/connect_with_facebook"
fb:login_text="@string/connect_with_facebook"
fb:logout_text="Connecting with facebook" />
Run Code Online (Sandbox Code Playgroud)
它总是说登录或注销.我该如何使用这个属性?我尝试通过LoginButton代码进行调试但是徒劳无功.它永远不会通过LoginButton()的任何构造函数,因此无法解析我的自定义参数.
有人面对这个问题吗?
小智 16
解决了!!
将名为"com_facebook_loginview_log_in_button"的字符串添加到位于res> values> strings.xml中的strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="com_facebook_loginview_log_in_button">Connect</string>
<string name="com_facebook_loginview_log_out_button">Your Logout</string>
</resources>
Run Code Online (Sandbox Code Playgroud)
你的第一个解决方案是正确 它没有用,因为你已经定义了样式atrribute:
style="@style/com_facebook_loginview_default_style"
Run Code Online (Sandbox Code Playgroud)
从LoginButton源代码:
public LoginButton(Context context, AttributeSet attrs) {
super(context, attrs);
if (attrs.getStyleAttribute() == 0) {
do stuff ...
}
}
Run Code Online (Sandbox Code Playgroud)
因此,如果您将"style"属性保留为undefined,它将仅查看已定义的属性"login_text".
加布里埃尔是当场。要解决此问题,请转到 Facebook SDK 中的 LoginButton.java 并移动 parseAttributes 调用
parseAttributes(attrs)
Run Code Online (Sandbox Code Playgroud)
到底部,以便它始终运行。
整个方法将如下所示:
public LoginButton(Context context, AttributeSet attrs) {
super(context, attrs);
if (attrs.getStyleAttribute() == 0) {
// apparently there's no method of setting a default style in xml,
// so in case the users do not explicitly specify a style, we need
// to use sensible defaults.
this.setTextColor(getResources().getColor(R.color.com_facebook_loginview_text_color));
this.setTextSize(TypedValue.COMPLEX_UNIT_PX,
getResources().getDimension(R.dimen.com_facebook_loginview_text_size));
this.setPadding(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_left),
getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_top),
getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_right),
getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_padding_bottom));
this.setWidth(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_width));
this.setHeight(getResources().getDimensionPixelSize(R.dimen.com_facebook_loginview_height));
this.setGravity(Gravity.CENTER);
if(isInEditMode()) {
// cannot use a drawable in edit mode, so setting the background color instead
// of a background resource.
this.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
// hardcoding in edit mode as getResources().getString() doesn't seem to work in IntelliJ
loginText = "Log in";
} else {
this.setBackgroundResource(R.drawable.com_facebook_loginbutton_blue);
initializeActiveSessionWithCachedToken(context);
}
}
parseAttributes(attrs);
}
Run Code Online (Sandbox Code Playgroud)
现在,style 和login_text 都被考虑在内。对我来说效果很好。
| 归档时间: |
|
| 查看次数: |
9234 次 |
| 最近记录: |