【问题标题】:How to get styles from Android Resources class?如何从 Android 资源类中获取样式?
【发布时间】:2015-04-21 18:38:07
【问题描述】:

我在Android中的应用程序之间进行交换,我传递了一系列参数来自定义另一个应用程序(颜色,徽标等),但是我找不到我传递的样式,我只能找到drawables,颜色,布局。

有没有办法找到样式?

我在用这个

Intent intent = new Intent();
        intent.setClassName("com.app.to.call", "com.app.to.call.LoginActivity");
intent.putExtra("package", getPackageName());
intent.putExtra("style", R.style.AppTheme);
startActivity(intent);

来自我正在使用的其他应用

if(customization.getKeys().getString(Global.LINK_PACKAGE) == null) {
            customization = null;
        }else{
            Resources resources = getPackageManager().getResourcesForApplication(customization.getKeys().getString(Global.LINK_PACKAGE));
            container.setBackgroundColor(resources.getColor(customization.getKeys().getInt(Global.LINK_BACKGROUND_COLOR)));
            setTheme();//How can I get the style?
        }

customization.getKeys() 是我传递的键。

【问题讨论】:

    标签: android android-resources android-styles android-runtime


    【解决方案1】:

    请记住,两个应用程序之间的 R 类可以具有相同名称的变量但具有不同的值。我不建议在应用之间传递 R 值

    【讨论】:

    • 不推荐?这是一个很大的禁忌。
    • 大声笑我知道 XD,这就是为什么我将变量和包名称传递给另一个应用程序,以便我可以获得放置包的资源。 @ci_
    • @Rudy_TM 哦,我现在明白了。您是否尝试过resources.newTheme(),然后在返回的Resources.Theme 对象上调用applyStyle(resId, force)?见developer.android.com/reference/android/content/res/…,布尔值)
    • 我试过了,但是我从另一个应用程序传递的 resId 总是说“找不到”我对绘图或其他东西没有问题,只有这个小恶魔。 @ci_
    • @Rudy_TM 您能否准确地将您尝试的内容添加到问题中?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    相关资源
    最近更新 更多