【发布时间】:2014-06-12 18:55:51
【问题描述】:
在我的活动中,我维护了一个SuperActivity,我在其中设置了主题。
public class SuperActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MyTheme);
}
}
themes.xml
<!-- ImageBackround -->
<style name="Theme.MyTheme" parent="ThemeLight">
<item name="myBgColor">@color/translucent_black</item>
</style>
现在我想在我的一个子活动中获取这种颜色。
正如这个可能的answer 中提到的,我写道:
int[] attrs = new int[] { R.attr.myBgColor /* index 0 */};
TypedArray ta = ChildActivity.this.obtainStyledAttributes(attrs);
int color = ta.getColor(0, android.R.color.background_light);
String c = getString(color);
ta.recycle();
但是每次我得到的默认值是android.R.color.background_light 而不是R.attr.myBgColor。
我做错了。我是否传递了 ChildActivity.this 的错误上下文?
【问题讨论】:
标签: android android-theme