Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Facebook登录按钮以两种语言编程更改文本_Android_Facebook_Login - Fatal编程技术网

Android Facebook登录按钮以两种语言编程更改文本

Android Facebook登录按钮以两种语言编程更改文本,android,facebook,login,Android,Facebook,Login,Android应用程序。 我有一个视图,其中我添加了Facebook的登录按钮,我想添加我所需语言的自定义文本以及带有用户名和密码的表单。 我的应用程序有两种语言。当我打开包含我的按钮的活动时,它显示“使用Facebook登录”。 我更改了语言,然后按钮以指定的语言获取我的自定义文本。当我想在表单中写一些东西时,登录按钮的文本会变回“使用Facebook登录”。 是否有可能使文本的更改保持一致,从而永远不会更改回“使用Facebook登录”? 也许可以扩展LoginButton类,但我不知道如何

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

更新: 我找到了一个解决方案:扩展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);
        }
    }
}

您应该为不同的语言创建不同的strings.xml

阅读: