Would you like to know how to change the color of selected items, Actionbar?

Asked

Viewed 137 times

-2

Gostaria de saber como faço para mudar a cor dos itens selecionados

<!-- styles.xml -->    

<resources>

    <!--  Base do  tema da aplicação. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
    </style>

     <!-- Cor do Menu -->
    <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
        <item name="spinBars">true</item>
        <item name="color">@android:color/white</item>
    </style>

</resources>

<?xml version="1.0" encoding="utf-8"?>


<!-- color.xml -->    


<resources>

    <!--cor principal do aplicativo-->
    <color name="colorPrimary">#93662f</color>
    <color name="colorPrimaryDark">#3a1a0b</color>
    <color name="colorAccent">#93662f</color>

    <!--deslize para baixo atualizar a cor da animação-->
    <color name="orange">#FF9900</color>
    <color name="green">#009900</color>
    <color name="blue">#000099</color>
    <color name="red">#ff0015</color>

    <!--outra cor-->
    <color name="background_color">#e2e2e2</color>
    <color name="divider">#f2f2f2</color>
    <color name="text_color">#525252</color>
    <color name="white">#ffffff</color>

</resources>

1 answer

0

You can change the color of a View by pressing it (example: textView, button etc) by creating Selectors:

drawable/selector.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/custom_color"/>
    <corners android:radius="8dp"/>
</shape>

color/custom_color.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android
    <item android:color="@color/blue_bt_pressed" android:state_pressed="true" />
    <item android:color="@color/blue_bt"/>
</selector>

And in your View add:

android:background ="@drawable/selector

I don’t know how you can implement this in Actionbar but I hope this can help you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.