Android 中按下 Tab 的状态是什么

发布于 2024-09-19 20:14:59 字数 1277 浏览 4 评论 0原文

我试图让我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风苍溪 2024-09-26 20:14:59

以下是 Android 2.2 中的 tab_indicator.xml

<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/tab_unselected" />
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" />

    <!-- Pressed -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>

您没有任何 android:state_pressed="true" 的内容。尝试更改您的选择器,使其看起来更像 Android 使用的选择器。

Here is tab_indicator.xml from Android 2.2:

<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/tab_unselected" />
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_selected" />

    <!-- Focused states -->
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/tab_focus" />
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/tab_focus" />

    <!-- Pressed -->
    <item android:state_pressed="true" android:drawable="@drawable/tab_press" />
</selector>

You do not have anything where android:state_pressed="true". Try changing your selector to look a bit more like what Android uses.

末骤雨初歇 2024-09-26 20:14:59

这是 Android 的默认 tab_indicator.xml。从此 gitkernal。你必须维持所有这些状态。

<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_north_normal" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_selected" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_normal" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_selected" /> 

    <!-- Pressed --> 
    <item android:state_pressed="true" android:drawable="@drawable/ic_tab_north_normal" /> 
</selector> 

this is the default tab_indicator.xml for android. got from this gitkernal. you have to maintain all these states.

<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_north_normal" /> 
    <item android:state_focused="false" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_selected" /> 

    <!-- Focused states --> 
    <item android:state_focused="true" android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_normal" /> 
    <item android:state_focused="true" android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/ic_tab_north_selected" /> 

    <!-- Pressed --> 
    <item android:state_pressed="true" android:drawable="@drawable/ic_tab_north_normal" /> 
</selector> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文