Android custom selector for ActionBarToggleButton

空扰寡人 提交于 2019-12-20 04:22:05

问题


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.

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>

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

Thanks


回答1:


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>

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>

Example:

<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)



来源:https://stackoverflow.com/questions/43180473/android-custom-selector-for-actionbartogglebutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!