我正在开发一个Android应用程序,它有一个设置选项来更改语言。它工作正常,但谷歌登录按钮不会改变语言,直到我关闭应用程序并重新打开它。本地化谷歌登录按钮在运行时
这是onCreate方法的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
String language = "en";
if (Locale.getDefault().getLanguage().equals("es")) {
language = "es";
}
String languagePref = prefs.getString(activity.getResources().getString(R.string.settings_language_key), language);
Locale locale = new Locale(languagePref);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
setContentView(start_view);
SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
// Set the dimensions of the sign-in button.
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {
signInButton.setSize(SignInButton.SIZE_WIDE);
} else {
signInButton.setSize(SignInButton.SIZE_STANDARD);
}
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".StartActivity"
android:id="@+id/drawer_layout"
style="@style/StartViewDrawerContainer">
<RelativeLayout
style="@style/StartViewParentVertical">
<!-- Some GUI elements -->
<LinearLayout
style="@style/StartViewMainContainer">
<!-- More GUI elements -->
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
style="@style/StartViewSignInButton"/>
</LinearLayout>
</RelativeLayout>
<include layout="@layout/content_main" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
style="@style/StartViewNavigationView"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
此代码为每一个字符串文字而不是谷歌的按钮的伟大工程。
有没有什么办法来以编程方式本地化登录文本?
谷歌标志按钮它不是简单的按钮。你可以使用后添加谷歌GSM库如果你想改变谷歌签名按钮的语言比添加XML简单的按钮和设计像谷歌按钮比你可以改变谷歌登录按钮语言 –
我不明白你是什么意思,当你说加入谷歌GSM图书馆。你能给我更多的细节吗?谢谢! –
我想你想在你的应用中使用谷歌身份验证?比你想在你的gradle中使用这个库。编译'com.google.android.gms:play-services-auth:9.2.1' –