最近在使用Switch控件的时候。官方文档是这样的
<Switch
value={(this.state && this.state.switchValue) || false}
onValueChange={(value) => {
this.setState({switchValue: value})
}}
// Color props are iOS-only
// thumbTintColor={'white'} // Removes shadow
/>
重要的是其中的 Color props are iOS-only.. 就这尴尬了。
费了几分钟看了源码,发现Switch是封装的原生组件,安卓里对应的是SwitchCompat控件。所以,要修改颜色,最简单的就是添加Theme.
首先添加style
<style name="Color1SwitchStyle">
<item name="colorControlActivated">@color/white</item