Android自定义选择器,用于ActionBarToggleButton [英] Android custom selector for ActionBarToggleButton

查看:269
本文介绍了Android自定义选择器,用于ActionBarToggleButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使 ActionBarToggleButton 具有自定义选择器. 我有适用于移动设备和平板电脑设备的应用程序,现在我必须使其可用于电视设备.

I'm having trouble making ActionBarToggleButton having custom selector. I got app that works for mobile and tablet devices, and now I have to make it usable for TV devices.

为此,我必须添加一些自定义焦点选择器,该选择器比默认选择器更可见.

To do that I have to add some custom focus selector, that is more visible then default one.

应用程序将NavigationView用于抽屉,并在操作栏中打开按钮以将其打开.动作栏中还有其他项目.

App uses NavigationView for drawer and has toggle button in action bar that opens it. Also there are other items in action bar.

我已经设法通过以下方式更改了所有操作栏项目的选择器:

I have managed to change selectors for all action bar items except toggle button via:

<item name="android:actionBarItemBackground">@drawable/selectable_selector</item>

是否可以自定义ActionToggleButton. 我不需要更改箭头 drawable ,而只需更改默认选择器的颜色.

Is there a way to customize ActionToggleButton. I dont need to change arrow drawable, but only color of the default selector.

谢谢

推荐答案

API 21及更高版本中,您只需在工具栏主题中的style.xml中编写此项目:

In API 21 and more you only need to write this item in style.xml, in your Toolbar theme:

<item name="colorControlHighlight">@color/xxx</item>

但是在下层API 中,首先您应该在styles.xml中编写这种样式:

But in lower APIs, First you should write this style in your styles.xml:

<style name="MyToolbarTheme.Navigation" parent="@android:style/Widget">
    <item name="android:background">@drawable/selector_items</item>
    <item name="android:scaleType">center</item>
    <item name="android:minWidth">56.0dip</item>
</style>

然后将此项目添加到您的工具栏主题:

then add this items to your toolbar theme:

<item name="actionBarItemBackground">@drawable/selector_appbar</item>
<item name="toolbarNavigationButtonStyle">@style/MyToolbarTheme.Navigation</item>

示例:

<style name="MyToolbarTheme" parent="ThemeOverlay.AppCompat.Dark">
    <item name="android:textColorPrimary">#ffffff</item>
    <item name="android:textColorSecondary">#ffffff</item>
    <item name="actionBarItemBackground">@drawable/selector_appbar</item>
    <item name="toolbarNavigationButtonStyle">@style/MyToolbarTheme.Navigation</item>
</style>

(对不起我的英语不好)

(Sorry for my weak English)

这篇关于Android自定义选择器,用于ActionBarToggleButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆