[英]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.