selector中的state_selected不起作用:注意state_activated状态

2014年12月16日 Android 12条评论 阅读32436次
selector中的state_selected不起作用:注意state_activated状态
项目中遇到的问题。
N个功能的一排图标,放置到一个ListView中去显示,点击不同图标做相应功能的设置,为让用户更清楚明了知道现在设置是哪个功能,所以要加一个选择中的功能。
大体实现步骤
1.ListView中的图标在drawable中写出selector,该selector文件中列出了android:state_pressed的图片资源、state_selected的图片资源。
2.ListView的onItemClickedListener监听里,针对当前选择的view,调用view.selected(true)

遇到的问题
在ListView中的某个功能图标点击时,点击下去显示的是state_pressed的图片资源,但手离开后又变会了默认的图片资源。

解决问题
开始猜测是画面中存在的其他控件,如Button、SeekBar等抢占了焦点所以导致ListView中ListItem无法显示selected状态。
在布局文中控制处ListView外的其他控件全都加上android:focusable="true"使其不可获得焦点。
这样的结果并没解决问题,需求中想要的selected状态的图片还是没显示出来。
后来在StackOverflow网站中,找到了state_activated状态,于是就在selector的xml文件中加入了state_activated="true"的控制,结果问题解决了。

官网上的state_activated
定义在android.graphics.drawable.StateListDrawable类中对xml属性的android:state_activated做了如下说明
android:state_activated

State value for StateListDrawable, set when a view or its parent has been "activated" meaning the user has currently marked it as being of interest. This is an alternative representation of state_checked for when the state should be propagated down the view hierarchy.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol state_activated.

android.R.attr中的说明
public static final int state_activated

Added in API level 11
State value for StateListDrawable, set when a view or its parent has been "activated" meaning the user has currently marked it as being of interest. This is an alternative representation of state_checked for when the state should be propagated down the view hierarchy.

Must be a boolean value, either "true" or "false".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

Constant Value: 16843518 (0x010102fe)

注意事项
selector.xml中的state_activated状态属性必须在androidAPI-11及以上版本使用。
分享本文至:

WRITTEN BY

avatar
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

12 条评论

  1. avatar wethinkjerky

    <a href="http://www.ictbel.com/nike-lunarglide-6-photosynth-software-runninge">nike lunarglide 6 photosynth software</a> <a href="http://www.ioioland.com/nike-free-run-5.0-v4-mujeres-corriendo-zapatos-quality-schuhea">nike free run 5.0 v4 mujeres corriendo zapatos quality</a> <a href="http://www.sesliesenyurt.com/nike-flyknit-lunar-1-kvinder-s%C3%B8lv-r%C3%B8d-scarpeb">nike flyknit lunar 1 kvinder s酶lv r酶d</a> <a href="http://www.wethinkjerky.com/nike-air-max-95-green-spain-shoeso">nike air max 95 green spain</a> <a href="http://www.dadees.com/nike-flyknit-lunar-1-orange-nation-kurpesc">nike flyknit lunar 1 orange nation</a> <a href="http://www.pickwickcrc.com/nike-air-huarache-green-white-zapatost">nike air huarache green white</a>
    wethinkjerky http://www.wethinkjerky.com/

  2. avatar ruyvu424

    <a href="http://www.33ocbhxx.com/nike-flyknit-lunar-3-rose-verizon-obuva">nike flyknit lunar 3 rose verizon</a> <a href="http://www.ou5cxgy0.com/nike-blazer-marine-low-jam-butyc">nike blazer marine low jam</a> <a href="http://www.5m9w6ysn.com/nike-flyknit-lunar-1-menn-gr%C3%B8nn-svart-scarpeb">nike flyknit lunar 1 menn gr酶nn svart</a> <a href="http://www.6iqdfvgi.com/adidas-damian-lillard-2-gold-wei%C3%9F-kurpesf">adidas damian lillard 2 gold wei脽</a> <a href="http://www.nfnl51ta.com/adidas-indoor-soccer-messi-15.3-wei%C3%9F-blau-scarpea">adidas indoor soccer messi 15.3 wei脽 blau</a> <a href="http://www.p4vepcy8.com/asics-gel-noosa-tri-10-sort-beach-violet-obuvc">asics gel noosa tri 10 sort beach violet</a>
    ruyvu424 http://www.ruyvu424.com/

  3. avatar desmotivaciones

    <a href="http://www.eyesocal.net/air-max-90-hyperfuse-gelb-blau-chaussuresa">air max 90 hyperfuse gelb blau</a> <a href="http://www.eyhbc.net/nike-free-5.0-v4-dahombres-laufschuh-schwarz-naranja-butya">nike free 5.0 v4 dahombres laufschuh schwarz naranja</a> <a href="http://www.faceroot.net/nike-flynit-air-max-gr%C3%A5-butyc">nike flynit air max gr氓</a> <a href="http://www.factsandchicks.net/nike-lebron-12-low-marrone-argento-scarpeg">nike lebron 12 low marrone argento</a> <a href="http://www.floridadrugdeto.net/nike-air-force-1-mid-07-hommes-plimsolls-chaussuresb">nike air force 1 mid 07 hommes plimsolls</a> <a href="http://www.fracflow.net/air-jordan-29-verde-vtodasey-butya">air jordan 29 verde vtodasey</a>
    desmotivaciones http://www.desmotivaciones.net/

  4. avatar rr26ujnx

    <a href="http://www.8eqraqzg.com/lunarglide-6-barato-basebtodas-chaussuresf">lunarglide 6 barato basebtodas</a> <a href="http://www.2ihz9gpj.com/nike-roshe-run-insole-for-verkauf-los-angeles-obuvc">nike roshe run insole for verkauf los angeles</a> <a href="http://www.l4ohbay4.com/lunarglide-8-tout-noir-zombies-kurpesb">lunarglide 8 tout noir zombies</a> <a href="http://www.06eexrxg.com/flyknit-lunar-1-gr%C3%A5-kurpese">flyknit lunar 1 gr氓</a> <a href="http://www.2wfq945g.com/nike-roshe-run-eclipse-for-vendita-kurpesd">nike roshe run eclipse for vendita</a> <a href="http://www.7quwnxec.com/air-jordan-reveal-schwarz-orange-scarped">air jordan reveal schwarz orange</a>
    rr26ujnx http://www.rr26ujnx.com/

  5. avatar hajimeteguide

    <a href="http://www.dcssattorneys.com/nike-air-max-2015-femminile-in-esecuzione-scarpa-tv-schuhec">nike air max 2015 femminile in esecuzione scarpa tv</a> <a href="http://www.lubimochka.com/nike-free-3.0-v4-rosa-r%C3%B8d-schuheg">nike free 3.0 v4 rosa r酶d</a> <a href="http://www.mnkcruises.com/under-armour-curry-one-gituttio-bianca-kurpesc">under armour curry one gituttio bianca</a> <a href="http://www.rvogtphoto.com/maschio-salomon-xt-wings-3-nero-arancia-obuvg">maschio salomon xt wings 3 nero arancia</a> <a href="http://www.centerofsport.com/vibram-fivefingers-kso-amarillo-negro-scarpee">vibram fivefingers kso amarillo negro</a> <a href="http://www.famelabcyprus.com/air-jordan-1-retro-low-og-premium-ice-bl%C3%A5-valley-butya">air jordan 1 retro low og premium ice bl氓 valley</a>
    hajimeteguide http://www.hajimeteguide.com/

  6. avatar ypsirealtor

    <a href="http://www.drmilliecalko.com/kvinners-air-jordan-retro-3-bl%C3%A5-lilla-schuhec">kvinners air jordan retro 3 bl氓 lilla</a> <a href="http://www.jishnuguha.com/nike-air-max-ltd-rojo-negro-and-blanco-chaussurese">nike air max ltd rojo negro and blanco</a> <a href="http://www.joehalvorson.com/lebron-13-mid-argento-butyg">lebron 13 mid argento</a> <a href="http://www.proximityhome.com/air-jordan-retro-6-todas-amarillo-scarpea">air jordan retro 6 todas amarillo</a> <a href="http://www.samexllc.com/air-jordan-retro-5-b%C3%B8rn-gr%C3%A5-schuhec">air jordan retro 5 b酶rn gr氓</a> <a href="http://www.sandeneuhofer.com/nike-air-max-1-essential-turbo-vert-butyf">nike air max 1 essential turbo vert</a>
    ypsirealtor http://www.ypsirealtor.com/

  7. avatar cbchispana

    <a href="http://www.avalonsoccer.com/mackage-kay-fur-trim-down-coat-mackager">mackage kay fur trim down coat</a> <a href="http://www.jemegaupload.com/silver-purple-womens-nike-air-max-2016-shoes-sneakere">silver purple womens nike air max 2016 shoes</a> <a href="http://www.plugginto.com/bon-march%C3%A9-under-armour-curry-3-femmes-rose-footc">bon march茅 under armour curry 3 femmes rose</a> <a href="http://www.incommonblog.com/nike-air-max-1-blue-and-white-skox">nike air max 1 blue and white</a> <a href="http://www.uheita.com/nike-free-run-5.0-sizing-sportsd">nike free run 5.0 sizing</a> <a href="http://www.headmull.com/peacock-coach-wallet-coachr">peacock coach wallet</a>
    [url=http://www.cbchispana.com/]cbchispana[/url]

  8. avatar witeducates

    <a href="http://www.shipmancomm.com/jordan-future-royal-blue-jorden-shoesc">jordan future royal blue jorden</a> <a href="http://www.rahwindsor.com/nike-sb-dunk-low-kvinders-gr%C3%A5-trainersb">nike sb dunk low kvinders gr氓</a> <a href="http://www.weisseditions.com/nike-kobe-12-mens-yellow-green-skob">nike kobe 12 mens yellow green</a> <a href="http://www.healtobfree.com/lebron-13-all-black-13-mvp-sneakerb">lebron 13 all black 13 mvp</a> <a href="http://www.klarinetino.com/mackage-yara-coat-mackager">mackage yara coat</a> <a href="http://www.cantleylaw.com/mennns-nike-air-max-90-hvit-shoesn">mennns nike air max 90 hvit</a>
    witeducates http://www.witeducates.com/

  9. avatar 都市女生

    感谢分享

  10. avatar 威客百科

    感觉还哦是挺麻烦的啊

  11. avatar 王语双

    送IP来了!

欢迎留言




用户登录

sitemap