我正在处理的应用程序我已经将主要/暗/重点颜色设置为我想要的颜色,并且它们出现在正确的位置(如预期的那样).我有一个我正在使用的偏好活动,我希望preferenceswitch我使用的颜色会以强调颜色呈现.相反,它们呈现材料蓝绿色.我想知道这是Lollipop的默认行为,就像Kitkat那样是蓝色的吗?我甚至没有引用#009688代码中的任何颜色或我的colors.xml/ styles.xml.
colors.xml
<resources>
<color name="primary">#00BCD4</color>
<color name="primary_dark">#0097A7</color>
<color name="accent">#FFD740</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我会提供更多信息.我在这里看到了一些关于创建自定义内容的东西,但这真的有必要吗?
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();
}
}
Run Code Online (Sandbox Code Playgroud)
当您使用时AppCompat,您应该使用每个属性的非前缀版本 - 这可以确保它们在所有API级别上都可用(与android:那些仅适用于API21 +的版本不同):
<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>
Run Code Online (Sandbox Code Playgroud)