2015-09-18 52 views
0

Android应用程序。 我有一个视图,我在Facebook上添加了LoginButton,我想用我需要的语言和一个带有用户名和密码的表单添加自定义文本。 我的应用程序有两种语言。当我打开包含我的按钮的活动时,它显示“使用Facebook登录”。 我改变语言,然后按钮获取我的自定义文本在指定的语言。当我想要在表单中写入内容时,“登录”按钮中的文本将变回“使用Facebook登录”。 是否有任何可能性使文本更改一致,所以它永远不会变回“使用Facebook登录”? 也许扩展了LoginButton类,但我看不到如何。 我希望你能理解我的问题。这不需要代码。 谢谢你的帮助!Facebook登录按钮以2种语言编程改变文本

更新: 我找到了一个解决方案:扩展facebook登录按钮类并覆盖onLayout方法,如下面的代码。

public class CustomLoginButton extends LoginButton 
{ 
    Context mContext; 

    public CustomLoginButton(Context context) 
    { 
     super(context); 
     mContext = context; 
    } 

    public CustomLoginButton(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
     mContext = context; 
    } 

    public CustomLoginButton(Context context, AttributeSet attrs, int defStyle) 
    { 
     super(context, attrs, defStyle); 
     mContext = context; 
    } 


    @Override 
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) 
    { 
     super.onLayout(changed, left, top, right, bottom); 
     final String fbButtonLabel; 
     if (this.getId() == R.id.login_button) 
     { 
      fbButtonLabel = getActivity().getResources().getString(R.string.custom_login_text); 
      this.setText(fbButtonLabel); 
     } 
    } 
} 

回答