Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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 我可以根据客户类型更改应用程序徽标和颜色吗?_Android - Fatal编程技术网

Android 我可以根据客户类型更改应用程序徽标和颜色吗?

Android 我可以根据客户类型更改应用程序徽标和颜色吗?,android,Android,假设客户A希望他的应用程序是蓝色的,而用户B希望他的应用程序是红色的,这两个应用程序在执行时是相同的,除了颜色和图像徽标。因此,根据客户登录更改应用程序的颜色将违反谷歌的条款?在值文件夹a主题.xml文件(如样式.xml) 在那里,您可以定义2个或多个主题,这些主题的颜色可以稍后在应用程序中为某些类型的用户设置: <resources> <style name="AppTheme.White" parent="Theme.AppCompat

假设客户A希望他的应用程序是蓝色的,而用户B希望他的应用程序是红色的,这两个应用程序在执行时是相同的,除了颜色和图像徽标。因此,根据客户登录更改应用程序的颜色将违反谷歌的条款?

文件夹a
主题.xml
文件(如
样式.xml
) 在那里,您可以定义2个或多个主题,这些主题的颜色可以稍后在应用程序中为某些类型的用户设置:

<resources>
    <style name="AppTheme.White" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/white</item>
        ...
    </style>

    <style name="AppTheme.Black" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/black</item>
        ...
    </style>
</resources>
创建一个用于保存
状态的类,称为
实用程序。类

public class Utility {

    public static void setTheme(Context context, int theme) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        prefs.edit().putInt(context.getString(R.string.prefs_theme_key), theme).apply();
    }

    public static int getTheme(Context context) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        return prefs.getInt(context.getString(R.string.prefs_theme_key), 1);
    }
}
private final static int THEME_WHITE = 1;
private final static int THEME_BLACK = 2;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        updateTheme();
    }


public void updateTheme() {
        if (Utility.getTheme(getApplicationContext()) <= THEME_WHITE) {
            setTheme(R.style.AppTheme_White);
        } else if (Utility.getTheme(getApplicationContext()) == THEME_BLACK) {
            setTheme(R.style.AppTheme_Black);
        }
    }
TargetActivity.class
中,您将设置将
状态应用于特定用户类型的方法:

public void updateTheme() {
        if (Utility.getTheme(getApplicationContext()) <= 1) {
            setTheme(R.style.AppTheme_White);
        } else if (Utility.getTheme(getApplicationContext()) == 2) {
            setTheme(R.style.AppTheme_Black);
        }
    }
这就是您处理不同
主题的方式。我想你的问题现在已经得到了回答:)


注:为用户设置不同的颜色并不违反谷歌的条款。谷歌自己给每个字母赋予了不同的颜色

违反条款?我想不出任何颜色的改变会违反任何条款,为什么你认为可能?
private final static int THEME_WHITE = 1;
private final static int THEME_BLACK = 2;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        updateTheme();
    }


public void updateTheme() {
        if (Utility.getTheme(getApplicationContext()) <= THEME_WHITE) {
            setTheme(R.style.AppTheme_White);
        } else if (Utility.getTheme(getApplicationContext()) == THEME_BLACK) {
            setTheme(R.style.AppTheme_Black);
        }
    }