选择器继承

Kit*_*fer 9 android state selector

有没有办法从selectorAndroid中已知的s 继承?

我想扩展一个EditText并添加一个自定义状态,到目前为止,我理解使用onCreateDrawableState()方法进行.当一个选择器进入游戏时有一个简单的方法来使用默认选择器,只是添加我的而不是再次定义它们?

<?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>
Run Code Online (Sandbox Code Playgroud)

Gre*_*lli 4

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

因此,在您的情况下,您有一个自定义状态,因此如果您仅定义自定义状态适用的情况,您不能这样做:

<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>
Run Code Online (Sandbox Code Playgroud)

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