SwitchPreference 默认颜色
SwitchPreference default color
我正在处理的应用程序 我已将 primary/dark/accent 颜色设置为我想要的颜色,并且它们出现在正确的位置(如预期的那样)。不过,我有一个偏好 activity,我正在使用,我希望我正在使用的 preferenceswitch
的颜色会呈现为强调色。相反,它们以 material 蓝绿色呈现。我想知道 Lollipop 的这种默认行为,就像在 Kitkat 中一样是蓝色的吗?我什至没有在我的代码或 colors.xml
/ styles.xml
.
的任何地方引用 #009688
的颜色
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>
有什么想法吗?我会提供更多信息。我在这里看到了一些关于创建自定义内容的内容,但这真的有必要吗?
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+):
<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>
我正在处理的应用程序 我已将 primary/dark/accent 颜色设置为我想要的颜色,并且它们出现在正确的位置(如预期的那样)。不过,我有一个偏好 activity,我正在使用,我希望我正在使用的 preferenceswitch
的颜色会呈现为强调色。相反,它们以 material 蓝绿色呈现。我想知道 Lollipop 的这种默认行为,就像在 Kitkat 中一样是蓝色的吗?我什至没有在我的代码或 colors.xml
/ styles.xml
.
#009688
的颜色
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>
有什么想法吗?我会提供更多信息。我在这里看到了一些关于创建自定义内容的内容,但这真的有必要吗?
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+):
<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>