【发布时间】:2015-06-09 00:04:05
【问题描述】:
当我使用 XML 引用来引用所述主题时,在 PreferenceActivity 上实现主题似乎有问题。
我有 3 个 style.xml 的
- style.xml
- style.xml (v16)
- style.xml (v21)
这些中的每一个都在其相应的值目录中。
为了应用这个主题,我在我的清单中引用它?attr/inst_theme
我当然会引用inst_theme作为主题名称。 这在 API 16 中完美运行 但是....
当我在 API 21 上试用主题时,它看起来像这样。
但它应该看起来像这样 我通过更改 V21 inst_theme 名称并将其与清单中的 @style/inst_theme 一起使用来实现这一点
另一个但是...
同时在 API 16 上使用以下设置:
这真的不需要澄清。
我根据this Thread设置我的偏好活动
PreferenceActivity 类代码:
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
Toolbar bar;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.pref_toolbar, root, false);
root.addView(bar, 0);
} else {
ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
ListView content = (ListView) root.getChildAt(0);
root.removeAllViews();
bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.pref_toolbar, root, false);
int height;
TypedValue tv = new TypedValue();
if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
}else{
height = bar.getHeight();
}
content.setPadding(0, height, 0, 0);
root.addView(content);
root.addView(bar);
}
bar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
inst_theme(与 v16 相同)
<style name="inst_theme" parent="AppBaseTheme">
<item name="android:background">@drawable/jrw_back_material_empty</item>
<item name="android:textColorTertiary">@color/pref_summary</item>
</style>
inst_theme (v21)
<style name="inst_theme" parent="AppBaseTheme">
<item name="android:windowBackground">@color/grijswit</item>
<item name="android:colorPrimary">@color/jumbo_main_2</item>
<item name="android:colorPrimaryDark">@color/antraciet</item>
<item name="android:textColorPrimary">@color/pref_name</item>
<item name="android:textColorSecondary">@color/pref_name</item>
<item name="android:textColorTertiary">@color/pref_name</item>
<item name="android:textColor">@color/pref_summary</item>
<item name="android:preferenceCategoryStyle">@style/pref_style</item>
</style>
<style name="pref_style" parent="AppBaseTheme">
<item name="android:layout">@layout/pref_cat_style</item>
</style>
pref_cat_style.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="48dp"
android:gravity="center_vertical"
android:textColor="@color/jumbo_main_2"
android:textStyle="bold"
style="@style/TextAppearance.AppCompat.Body1"/>
AppBase主题:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
我希望你能帮我解决这个问题,我只是看不出我做错了什么,所有其他样式都被每个 API 使用得很好。
提前谢谢你:)
【问题讨论】:
标签: android xml reference themes android-preferences