how to highlight a menu item on selection? [duplic

2019-02-23 15:27发布

问题:

This question already has an answer here:

  • How to remove blue glow from Sherlock action bar menu item? 1 answer

How to highlight menu item on selection, I tried modifying styles.xml with various attributes like colorPressedHighlight, colorActivatedHighlight, etc. Is there any way to keep the menu item focussed until other item is selected?

AndroidManifest.xml:

<style name="onPressedHighLight" parent="AppBaseTheme">
    <item name="android:colorActivatedHighlight">@color/OnPressed</item>
</style>
<color name="OnPressed" parent="AppBaseTheme">#FF0000</color>

Activity file:

setTheme(R.style.onPressedHighLight);

回答1:

Use selector for custom buttons. Search in google for more examples. Here is one.