Tag: 颜色

如何改变SwitchCompat的轨道颜色

我试过使用下面的链接来改变SwitchCompat的颜色: 如何改变一个SwitchCompat的颜色 注意我的开关中的低对比度: 但是,在更改所有相关的颜色值后,SwitchCompat的轨道(较亮的灰色)保持不变。 除了颜色,我不想改变外观。 拇指是粉红色的,我希望轨道有一些对比。 我想在我的styles.xml中定义一个值吗? 我试过这些值(随机的非白色): <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/first</item> <item name="colorPrimaryDark">@color/second</item> <item name="colorAccent">@color/third</item> … <item name="colorControlActivated">@color/first</item> <item name="colorControlHighlight">@color/first</item> <item name="colorControlNormal">@color/second</item> <item name="colorSwitchThumbNormal">@color/second</item> <item name="colorButtonNormal">@color/second</item> …>

如何用十六进制值更改CheckedTextView的Checked Tint Color

我想在checked视图的状态时动态地改变CheckedTextView的色调。 我很确定我可以通过在CheckedTextView上调用setCheckMarkTintList来实现这CheckedTextView 。 要做到这一点,我需要一个ColorStateList ,但问题是我想保留CheckedTextView每个状态的所有颜色,除了checked状态。 所以,我可以获得ColorStateList的CheckedTextView ,但是我不知道只能更改checked状态的颜色。 我知道我可以创建一个新的ColorStateList ,但是如何确保它保留了原始的所有值? 我可以像这样创建一个状态列表: int[][] states = new int[][] { new int[]{android.R.attr.state_pressed}, new int[]{-android.R.attr.state_pressed}, new int[]{android.R.attr.state_focused}, new int[]{-android.R.attr.state_focused}, new int[]{android.R.attr.state_selected}, new int[]{-android.R.attr.state_selected}, new int[]{android.R.attr.state_checkable}, new int[]{-android.R.attr.state_checkable}, new int[]{android.R.attr.state_checked}, new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_enabled}, new int[]{-android.R.attr.state_enabled}, new int[]{android.R.attr.state_window_focused}, new int[]{-android.R.attr.state_window_focused}, new int[]{} // default state } 并从原始ColorStateList的颜色创建一个颜色列表: int[] colors = new […]

根据背景颜色确定字体颜色

给定一个系统(例如一个网站),让用户自定义一些部分的背景颜色,但不是字体颜色(保持选项的数量最少),有没有一种方法来编程确定是否“光”或“黑暗“的字体颜色是必要的? 我确定有一些算法,但是我对颜色,光度等知之甚少,无法自行解决。