简体   繁体   English

无法设置ActionBar项目的样式?

[英]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. 我想设置放置在ActionBarToggleButton样式,但似乎无法这样做。 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: 我尝试遵循以下步骤: Android切换按钮自定义外观,但似乎不起作用这是我的尝试:

create_post_menu.xml 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 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. 您可以参考以下问题: ToggleButtons作为actionBar自定义视图,表现怪异。 Maybe it can help you for resolve your issue is custion toggle button when setup action bar 也许可以帮助您解决问题,请在设置操作栏时使用“ custion”切换按钮

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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