简体   繁体   中英

Can't style ActionBar Item?

I want to style a ToggleButton that I placed in my ActionBar but I can't seem to do so. I have tried to apply a simple background to it but that doesn't seem to work. I tried to follow this: Android toggle button custom look but that didn't seem to work Here was my attempt:

create_post_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".CreatePost">

    <item
        android:id="@+id/toggle_test"
        android:title="Private"
        app:showAsAction="always"
        android:orderInCategory="1"
        android:background="@drawable/pick_out_line"
        app:actionViewClass="android.widget.ToggleButton" />
</menu>

pick_out_line.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/white" android:state_checked="true" />
    <item android:drawable="@color/white" android:state_pressed="true" />
    <item android:drawable="@color/colorPrimary" />
</selector>

You can refer to this question : ToggleButtons as actionBar custom view behaving weirdly. Maybe it can help you for resolve your issue is custion toggle button when setup action bar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM