[英]Change Switch color in Navigation Drawer menu item
我无法更改导航抽屉开关项目的颜色。 我希望每个人都有一个与其动作相关的自定义颜色。
我用这样的菜单定义了我的导航抽屉:
<item
android:title="@string/nav_drawer_services_title">
<menu>
<group android:checkableBehavior="none">
<item
android:id="@+id/Red_selector"
android:title="@string/nav_drawer_red_title"
app:actionLayout="@layout/switch_layout"/>
<item
android:id="@+id/Blue_selector"
android:title="@string/nav_drawer_blue_title"
app:actionLayout="@layout/switch_layout"/>
</group>
</menu>
</item>
我的switch_layout.xml是这样的:
<Switch
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:onClick="toggleService"
android:checkable="true"
android:checked="true"
style="@style/MyCustomSwitchTheme"
/>
我已经尝试过更改MyCustomSwitchTheme
如下所示: 更改Switch的“on”颜色 ,但开关项目保持相同的颜色。
为什么我的自定义主题样式不会覆盖默认值? 我似乎无法从colors.xml
和AppTheme
定义的colorAccent
更改这些开关。
有人知道解决这个问题吗?
编辑:这是样式代码,抱歉不包括OP。
<style name="MyCustomSwitchTheme">
<!-- active thumb & track color (30% transparency) -->
<item name="colorControlActivated">#46bdbf</item>
<!-- inactive thumb color -->
<item name="colorSwitchThumbNormal">@color/light_gray_color</item>
<!-- inactive track color (30% transparency) -->
<item name="android:colorForeground">#42221f1f</item>
</style>
只需使用android:theme="@style/MyCustomSwitchTheme"
而是style="@style/MyCustomSwitchTheme"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.