SwitchPreference 默认颜色 [英] SwitchPreference default color
问题描述
我正在处理的应用程序我已将原色/深色/强调色设置为我想要的颜色,并且它们出现在正确的位置(如预期).我有一个我正在使用的偏好活动,我希望我使用的 preferenceswitch
的颜色会以强调色呈现.相反,它们以材料青色进行渲染.我想知道 Lollipop 的这种默认行为,就像 Kitkat 中的蓝色一样吗?我什至没有在我的代码或我的 colors.xml
/styles.xml
的任何地方引用 #009688
的颜色.
the application I am working on I have set the primary/dark/accent colors to the colors I desire and they appear in the correct locations (as expected). I have a preference activity that I am using though, and I was hoping that the color of the preferenceswitch
's that I am using would render in the accent color. Instead they are rendering in the material teal color. I was wondering is this default behavior with Lollipop, like in Kitkat it was the blue? I don't even reference the color which is #009688
anywhere in my code or my colors.xml
/ styles.xml
.
colors.xml
<resources>
<color name="primary">#00BCD4</color>
<color name="primary_dark">#0097A7</color>
<color name="accent">#FFD740</color>
</resources>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary">@color/primary</item>
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<item name="android:colorAccent">@color/accent</item>
</style>
</resources>
有什么想法吗?我会提供更多信息.我在这里看到了一些关于创建自定义内容的内容,但这真的有必要吗?
Any Ideas? I'll provide any more info. I saw some stuff on here about creating custom stuff, but is that really necessary?
preferenceActivity.java
public class PreferenceActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PrefFrag prefFragment = new PrefFrag();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(android.R.id.content, prefFragment);
fragmentTransaction.commit();
}
}
推荐答案
当您使用 AppCompat
时,您应该使用每个属性的非前缀版本 - 这确保它们在所有 API 上可用级别(与 android:
不同,例如仅适用于 API21+):
When you use AppCompat
, you should use the non-prefixed versions of each attribute - this ensures that they are available on all API levels (unlike the android:
ones, which only work on API21+ for example):
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
这篇关于SwitchPreference 默认颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!