Android 中按下 Tab 的状态是什么
我试图让我的 tabicon 在按下选项卡时发生变化(即当您按下选项卡时它会改变颜色,但尚未释放)。我创建了一个选择器,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon1" />
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon2" />
<!-- Focused states -->
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon3" />
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon4" />
<!-- Pressed -->
<item android:state_pressed="true"
android:drawable="@drawable/ic_tab_icon5" />
</selector>
但是,由于某种原因,仅达到前两个状态(仅使用 icon1 和 icon 2)。谁能告诉我“按下但未选择”选项卡的正确状态是什么?
*编辑以澄清新情况
I'm trying to get my tabicon to change when a tab is pressed (i.e. when it changes color when you press the tab, but haven't released yet). I've created a selector as follows:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon1" />
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon2" />
<!-- Focused states -->
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon3" />
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/ic_tab_icon4" />
<!-- Pressed -->
<item android:state_pressed="true"
android:drawable="@drawable/ic_tab_icon5" />
</selector>
However, for some reason only the first two states are reached (only icon1 and icon 2 are used). Can anyone tell me what the correct state is for a "pressed but not selected" tab?
*Edited to clarify new situation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是 Android 2.2 中的
tab_indicator.xml
:您没有任何
android:state_pressed="true"
的内容。尝试更改您的选择器,使其看起来更像 Android 使用的选择器。Here is
tab_indicator.xml
from Android 2.2:You do not have anything where
android:state_pressed="true"
. Try changing your selector to look a bit more like what Android uses.这是 Android 的默认
tab_indicator.xml
。从此 gitkernal。你必须维持所有这些状态。this is the default
tab_indicator.xml
for android. got from this gitkernal. you have to maintain all these states.