我要做的是在Firebase的RemoteConfig中保存colorPrimay,colorDarkPrimary等值,以便我能够从远程配置更改应用程序的颜色,并且我做了以下操作
更新: 我想要做的是在Firebase的RemoteConfig中保存colorPrimay,colorDarkPrimary等值,以便我能够从远程confi更改应用程序的颜色。我怎么能这样做?
更新:
我尝试过的是
<--!remote_config_default.xml!-->
<defaultsMap>
<entry>
<key>primaryColor</key>
<value>#9c27b0</value>
</entry>
<entry>
<key>colorPrimaryDark</key>
<value>#7b1fa2</value>
</entry>
<entry>
<key>colorAccent</key>
<value>#FF4081</value>
</entry>
<entry>welcomeMessage</entry>
<value>Connection Failed</value>
并像这样获取
void applyRemoteConfig() {
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_default);
// cacheExpirationSeconds is set to cacheExpiration here, indicating that any previously
// fetched and cached config would be considered expired because it would have been fetched
// more than cacheExpiration seconds ago. Thus the next fetch would go to the server unless
// throttling is in progress. The default expiration duration is 43200 (12 hours).
int cacheExpiration = 1000;
final String TAG = "Riddles";
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "Fetch Succeeded");
// Once the config is successfully fetched it must be activated before newly fetched
// values are returned.
mFirebaseRemoteConfig.activateFetched();
} else {
Log.d(TAG, "Fetch failed");
String message = mFirebaseRemoteConfig.getString("welcomeMessage");
displayWelcomeMessage(message);
Log.d(TAG, message);
}
}
});
String message = mFirebaseRemoteConfig.getString("welcomeMessage");
displayWelcomeMessage(message);
Log.d(TAG, message);
}
但是
mFirebaseRemoteConfig.getString("colorPrimary");
mFirebaseRemoteConfig.getString("colorDarkPrimary");
mFirebaseRemoteConfig.getString("welcomeMessage");
正在返回Null。
答案 0 :(得分:2)
您可以将其添加到远程配置文件中。
<!-- color entries -->
<entry>
<key>color_primary</key>
<value>#3F51B5</value>
</entry>
<entry>
<key>color_primary_dark</key>
<value>#303F9F</value>
</entry>
要动态更改应用的颜色,请使用远程配置提供的标记,然后使用fetch()
进行更改。对于精心实施refer to this.