【问题标题】:Selector inherit选择器继承
【发布时间】:2011-12-01 14:52:08
【问题描述】:

有没有办法从 Android 中已知的selectors 继承?

我想扩展一个EditText 并添加一个自定义状态,到目前为止我理解使用onCreateDrawableState() 方法。 When an selector comes into play is there an easy way to use the default selectors and just add mine instead of defining them again ?

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.my.package">

<item android:state_enabled="false" android:drawable="@drawable/login_textfield_bg_error" />
<item android:state_window_focused="false" android:drawable="@drawable/login_textfield_bg_error">
<item android:state_pressed="true" android:drawable="@drawable/login_textfield_bg_error" />
<item android:state_selected="true" android:drawable="@drawable/login_textfield_bg_error" />
<item app:errorBackground="@drawable/login_textfield_bg_error" />
</selector>

【问题讨论】:

    标签: android selector state


    【解决方案1】:

    我可能会误解,但也许你可以直接委托给他们?

    所以在你的情况下你有一个自定义状态,所以如果你只定义你的自定义状态适用的情况,你不能这样做:

    <selector xmlns:android="..." xmlns:app="...">
      <item app:custom_state="true" android:drawable="@drawable/the_one_care_about"/>
      <item android:drawable="@android:drawable/editbox_background"/>
    </selector>
    

    所以这基本上表明,对于我的自定义状态为真的状态,显示我的自定义背景......但是对于所有其他状态,行为与此选择器相同。这个选择器恰好有其他状态的说明,所以也要遵循它们。所以没有重新定义,并且由于状态是按从上到下的顺序评估的,所以从技术上讲,您不必重新定义任何东西,您只是说您只想定义状态的子集并委托给另一个可绘制对象(恰好成为另一个选择器)用于所有其他内容。这有帮助吗?

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多