我正在创建一个应用程序,其中我在操作栏中有三个项目。我希望当我单击其中一个项目时,它应该突出显示。
我浏览了几个可用的示例,但得出的结论是我必须使用 ActionBar 样式生成器工具创建样式。
我参考了以下链接..但不满意
这是唯一的方法吗?
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:actionBarItemBackground">@drawable/action_bar_item_selector</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
选择器.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:drawable="@drawable/ic_action_blue" />
<item android:state_pressed="true"
android:drawable="@drawable/ic_action_green" />
<item android:drawable="@android:color/transparent" />
</selector>
但是选择不会像 state_pressed 和 state_focused 那样停滞不前。
我希望该项目保持突出显示,直到用户进行该活动。