阅读较新的主题属性在旧平台属性、主题、平台

2023-09-04 08:36:55 作者:浅若゛梨花落

我想读的主题和风格而设计的平台属性值中出现不到我上运行我的应用程序。

请不要问为什么。如果你知道我写那么库什么,你应该已经知道我喜欢推平台的功能:)的

我下presumption操作,当机器人样式被编译属性常数是什么用于键,因此,理论上能够被读取在任何平台上不知。这是我观察到与布局XMLS发生在我的其他库,没有麻烦。

下面是一个基础测试用例,显示的问题。这应该采用Android 3.0 +进行编译。

 <资源>
    <样式名称=Theme.BreakMe>
        <项目名称=机器人:actionBarStyle> @风格/ Widget.BreakMe< /项目>
    < /风格>
    <样式名称=Widget.BreakMe父=机器人:小工具>
        <项目名称=机器人:填充> 20dp< /项目>
    < /风格>
< /资源>
 

这本使用 Android的事实:actionBarStyle 特别是irreleveant。所有这一切应该理解的是,它这是唯一可用的属性开始与Android 3.0。

怎样才能删除属性 主题 主题下面的网址连接

下面是我曾尝试在平台上的到Android 3.0之前

迄今为止访问这些值的方式

 <的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=打倒我
    风格=机器人:ATTR / actionBarStyle
    />
 

 <申报,设置样式名称=不管>
    <项目名称=datStyle格式=参考/>
< /申报,设置样式>

<样式名称=Theme.BreakMe.Take2>
    <项目名称=datStyle>安卓?ATTR / actionBarSize< /项目>
< /风格>

<的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=打倒我
    风格=?ATTR / datStyle
    />
 

 的TypedValue outValue =新的TypedValue();
。context.getTheme()resolveAttribute(android.R.attr.actionBarStyle,outValue,真正的);
 

  INT []主题=新INT [] {android.R.attr.actionBarSize};
INT Theme_actionBarSize = 0;
TypedArray A = context.obtainStyledAttributes(ATTRS,主题);
INT REF = a.getResourceId(Theme_actionBarSize,0);
 

  TypedArray A = context.obtainStyledAttributes(ATTRS,R.styleable.ActionBar,android.R.attr.actionBarStyle,0);
 

所有这些导致LogCat中此错误:

  E /的ResourceType(5618):风格包含有坏输入键:0x010102ce
 

0x010102ce 常数的属性值 android.R.attr.actionBarStyle 这似乎预示着平台被拒绝的属性之前,我甚至可以得到一个机会来访问它的价值。

我要寻找从主题看这样的属性,任何其他方式。我相当肯定,一旦我得到的样式参考,我不会有麻烦阅读它的属性。

是否有任何可能的方式来做到这一点?

解决方案   

我下presumption操作,当机器人样式被编译属性常数是什么用于键,因此,理论上能够被读取在任何平台上不知何故

可能,虽然这不是我怎么了跨preting C ++源$ C ​​$ C引发你所看到的错误。看看 ResTable ::主题:: applyStyle()框架/基/库/ utils的/ ResourceTypes.cpp

我的跨pretation是,Android有什么相当于一个内存中的表的包 - >类型 - >可能的条目:

  numEntries = curPI->类型[T] .numEntries;
 

您进入指数高于已知最高的条目:

 如果(E> = numEntries){
    LOGE(风格包含有坏输入键:为0x%08X \ N,attrRes);
    包++;
    继续;
}
 

这是可能的,他们处理这个不同的机器人与其他套餐 - 机器人使用已知值的固件建立时间(和你产生的入口指数较高,因为它是一个新的平台),非 - 机器人那些假设任何事情的有效

如果我的猜测是正确的,你想干什么都不行的东西。话虽这么说,我的C ++的日子的认真的在我的后视镜,我可能是misinter preting我所看到的。

I am trying to read attribute values from themes and styles which were designed for platforms that are newer than I am running my application on.

Please don't ask why. If you know anything about the libraries I write then you should already know that I like to push the capabilities of the platform :)

I am operating under the presumption that when Android styles are compiled the attribute constants are what is used for the keys and therefore should theoretically be able to be read on any platform somehow. This is what I have observed to be happening with layout XMLs in my other libraries with no trouble.

Here is a base test case which shows the problem. This should be compiled using Android 3.0+.

<resources>
    <style name="Theme.BreakMe">
        <item name="android:actionBarStyle">@style/Widget.BreakMe</item>
    </style>
    <style name="Widget.BreakMe" parent="android:Widget">
        <item name="android:padding">20dp</item>
    </style>
</resources>

The fact that this uses android:actionBarStyle specifically is irreleveant. All that should be understood is that its an attribute which was only available starting with Android 3.0.

Here are the way that I have tried to access these values thus far on platforms prior to Android 3.0.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Break Me"
    style="?android:attr/actionBarStyle"
    />

and

<declare-styleable name="Whatever">
    <item name="datStyle" format="reference" />
</declare-styleable>

<style name="Theme.BreakMe.Take2">
    <item name="datStyle">?android:attr/actionBarSize</item>
</style>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Break Me"
    style="?attr/datStyle"
    />

and

TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.actionBarStyle, outValue, true);

and

int[] Theme = new int[] { android.R.attr.actionBarSize };
int Theme_actionBarSize = 0;
TypedArray a = context.obtainStyledAttributes(attrs, Theme);
int ref = a.getResourceId(Theme_actionBarSize, 0);

and

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionBar, android.R.attr.actionBarStyle, 0);

All of them result in this error in LogCat:

E/ResourceType(5618): Style contains key with bad entry: 0x010102ce

The 0x010102ce constant is the attribute value of android.R.attr.actionBarStyle which seems to indicate the platform is rejecting the attribute before I can even get a chance to access its value.

I am looking for any other way to read attributes like this from the Theme. I'm fairly sure that once I've obtained the style reference I won't have trouble reading its attributes.

Is there any possible way to do this?

解决方案

I am operating under the presumption that when Android styles are compiled the attribute constants are what is used for the keys and therefore should theoretically be able to be read on any platform somehow.

Possibly, though that is not how I am interpreting the C++ source code that raises the error you are seeing. Check out ResTable::Theme::applyStyle() in frameworks/base/libs/utils/ResourceTypes.cpp.

My interpretation is that Android has what amounts to an in-memory table of packages->types->possible entries:

numEntries = curPI->types[t].numEntries;

Your entry index is higher than the highest known entry:

if (e >= numEntries) {
    LOGE("Style contains key with bad entry: 0x%08x\n", attrRes);
    bag++;
    continue;
}

It is possible that they handle this different for android versus other packages -- android uses known values at firmware build time (and your generated entry index is higher, because it is from a newer platform), non-android ones assume anything's valid.

If my guesswork is correct, what you want to do will not work. That being said, my C++ days are seriously in my rear-view mirror, so I may be misinterpreting what I'm seeing.