选择继承 [英] Selector inherit
问题描述
有没有办法从继承已知选择
S在Android的?
我想扩展一个的EditText
并添加了一个自定义的状态,到目前为止,我的理解用做它的 onCreateDrawableState()
方法。当选择进场有一种简单的方法来使用默认的选择,只是又增加定义它们的煤矿呢?
< XML版本=1.0编码=UTF-8&GT?;
<选择的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res/com.my.package>
<项目安卓state_enabled =假机器人:可绘制=@可绘制/ login_textfield_bg_error/>
<项目安卓state_window_focused =假机器人:可绘制=@可绘制/ login_textfield_bg_error>
<项目的android:STATE_ pressed =真正的机器人:可绘制=@可绘制/ login_textfield_bg_error/>
<项目安卓state_selected =真正的机器人:可绘制=@可绘制/ login_textfield_bg_error/>
<项目的应用程序:errorBackground =@可绘制/ login_textfield_bg_error/>
< /选择器>
我可能会被误解,但也许你可以只是简单委托给他们?
因此,在你的情况,你有一个自定义的状态,所以如果你只定义情况下,您的自定义状态适用于你不能做到这一点:
<选择的xmlns:机器人=...的xmlns:程序=...>
<项目的应用程序:custom_state =真正的机器人:可绘制=@可绘制/ the_one_care_about/>
<项目机器人:可绘制=@机器人:可绘制/ editbox_background/>
< /选择器>
所以这基本上是国家,各州在那里我自定义的状态为真,显示我的自定义背景......然而,对于所有其他国家的行为与此相同选择。这种选择只是恰巧有其他国家说明,以便跟着他们了。因此,有没有重新定义,并且由于状态在从上到下的顺序计算的,你在技术上不必重新定义什么,你只是说明你只是想定义状态的一个子集,并委托给该其他绘制(这恰好是另一个选择器)的所有其他内容。这是否帮助?
Is there a way to inherit from already known selector
s in Android ?
I would like to extend an EditText
and added an custom state, so far i understood doing it using the onCreateDrawableState()
Method. 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>
I might be misunderstanding but maybe you can just plain delegate to them?
So in your case you have a custom state, so if you define only the cases where your custom state applies can't you do this:
<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>
So this basically states, for states where my custom state is true, show my custom background... however for all other states, behave the same as this selector. This selector just so happens to have instructions for other states so follow them too. So there is no redefining and since the states are evaluated in top to bottom order, you technically don't have to redefine anything, you are just stating you only want to define a subset of states and delegate to this other drawable (which happens to be another selector) for all other content. Does this help?
这篇关于选择继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!