android:state_enabled="false"无效

3
这是我的选择器:
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:drawable/ic_delete" 
     android:state_enabled="false"
     android:state_selected="false" />
    <item android:drawable="@android:drawable/arrow_up_float"
     android:state_selected="true"
     android:state_enabled="true" />
    <item android:drawable="@drawable/modosprepara"
     android:state_enabled="true"
     android:state_selected="false" />
    </selector>

"arrow_up_float"和"modosprepara"可以正常使用,但是"ic_delete"从未出现。我使用以下代码来禁用此视图:
    tabs.getTabWidget().getChildAt(index).setEnabled(false);

状态是否选择=false? - Blackbelt
是state_enabled没有起作用。 - Aythami
4
很久以前我遇到过类似的问题,结果发现状态的顺序很重要。通过改变顺序,问题得以解决。因此,尝试将state_selected切换到第一条语句,也许会有帮助。 - Opiatefuchs
我尝试了很多种方法,很多种顺序,但是什么都不行...一点反应也没有 :/ 我认为它没有识别视图的状态(启用或禁用)... - Aythami
感谢 @Opiatefuchs。愚蠢的安卓... - Youngjae
2个回答

3

您必须按照顺序执行以下步骤:

1)state_enabled = true

2)state_enabled = false

3)state_pressed = true

4)state_pressed = false


0

我刚刚找到了一个解决方案

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/modosprepara"
     android:state_activated="true"/>
    <item android:drawable="@android:drawable/arrow_up_float"
     android:state_selected="true" />
    <item android:drawable="@android:drawable/ic_delete" />
    </selector>

并且

    tabs.getTabWidget().getChildAt(index).setEnabled(false);
    tabs.getTabWidget().getChildAt(index).setActivated(false);

感谢您的回答!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接