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

2014年12月16日 Android 19条评论 阅读39474次
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
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

19 条评论

  1. <a href="http://www.konajerrysbbq.com/louboutin-boots-learning-inventory-louboutine">louboutin boots learning inventory</a> <a href="http://www.luminorama.com/hermes-bag-kuwait-2016-hermesc">hermes bag kuwait 2016</a> <a href="http://www.greatratesrus.com/asics-gel-kinsei-4-schwarz-wei%C3%9F-neon-rosa-eye-footg">asics gel kinsei 4 schwarz wei脽 neon rosa eye</a> <a href="http://www.alldergi.com/parajumpers-kodiak-fit-kits-parajumpersa">parajumpers kodiak fit kits</a> <a href="http://www.youcampnh.com/moncler-coats-on-sale-uk-only-monclera">moncler coats on sale uk only</a> <a href="http://www.wmuhishouse.com/mizuno-wave-prophecy-noir-rose-chaussuresb">mizuno wave prophecy noir rose</a>
    countryabbey http://www.countryabbey.com/

  2. <a href="http://www.tasdizayni.com/canada-goose-citadel-parka-sverige-quiz-canadagoosea">canada goose citadel parka sverige quiz</a> <a href="http://www.blogtourney.com/asics-gel-noosa-tri-8-rosso-rosa-kurpese">asics gel noosa tri 8 rosso rosa</a> <a href="http://www.edgethrive.com/adidas-zx-700-violet-jaune-kit-kurpesa">adidas zx 700 violet jaune kit</a> <a href="http://www.kewauneecares.com/nike-kevin-zeitler-mens-black-elite-jersey-68-nfl-home-cincinnati-bengals-nflt">nike kevin zeitler mens black elite jersey 68 nfl home cincinnati bengals</a> <a href="http://www.resekipman.com/billig-nike-air-speed-turf-menns-gr%C3%A5-footg">billig nike air speed turf menns gr氓</a> <a href="http://www.robineliza.com/nike-hyperdunk-2014-femminile-blu-oro-chaussuresd">nike hyperdunk 2014 femminile blu oro</a>

  3. <a href="http://www.zanetarecords.com/olive-vert-ralph-lauren-t-shirt-poloa">olive vert ralph lauren t shirt</a> <a href="http://www.acesignsgroup.com/nike-hyperdunk-2015-flyknit-high-bianca-marrone-scarpek">nike hyperdunk 2015 flyknit high bianca marrone</a> <a href="http://www.barrylipscomb.com/dorothy-perkins-lila-blumen-kleid-dresse">dorothy perkins lila blumen kleid</a> <a href="http://www.adoseofdupas.com/adidas-damian-lillard-2-s%C3%B8lv-oransje-footi">adidas damian lillard 2 s酶lv oransje</a> <a href="http://www.dwnldmedia.com/kvinders-asics-gel-noosa-tri-10-hvid-sort-butyg">kvinders asics gel noosa tri 10 hvid sort</a> <a href="http://www.imistudio.com/parajumpers-long-bear-navy-blue-color-parajumpersb">parajumpers long bear navy blue color</a>
    dermiskincare http://www.dermiskincare.com/

  4. <a href="http://www.maninatravel.com/adidas-neo-skate-argento-rosso-runningf">adidas neo skate argento rosso</a> <a href="http://www.aroundbalkans.com/air-jordan-retro-28-dark-blau-orange-schuhei">air jordan retro 28 dark blau orange</a> <a href="http://www.taxrightllc.com/kentucky-wildcats-top-of-the-world-ncaa-grype-stretch-cap-hath">kentucky wildcats top of the world ncaa grype stretch cap</a> <a href="http://www.dlxcommerce.com/nike-air-max-2017-mujeres-verde-oro-trainersce">nike air max 2017 mujeres verde oro</a> <a href="http://www.wheelsongs.com/herren-adidas-schwarz-samba-trainers-schuhek">herren adidas schwarz samba trainers</a> <a href="http://www.asksohbetim.com/air-jordan-18-p%C3%BArpura-scarpeg">air jordan 18 p煤rpura</a>
    onthecar http://www.onthecar.com/

  5. <a href="http://www.gardensbyruth.com/air-max-lunar-90-schwarz-rosa-butyc">air max lunar 90 schwarz rosa</a> <a href="http://www.batemanafrica.com/roshe-runs-khaki-gr%C3%BCn-scarpeg">roshe runs khaki gr眉n</a> <a href="http://www.tritechems.com/air-jordan-1-mid-schwarz-and-rot-chaussuresb">air jordan 1 mid schwarz and rot</a> <a href="http://www.malocalguide.com/nike-air-max-tn-camello-butya">nike air max tn camello</a> <a href="http://www.indeeprecords.com/nike-air-max-360-diamond-griffey-schwarz-schuhee">nike air max 360 diamond griffey schwarz</a> <a href="http://www.clearancedept.com/mujeres-nike-free-3.0-verde-p%C3%BArpura-chaussurese">mujeres nike free 3.0 verde p煤rpura</a>
    codedtalk http://www.codedtalk.com/

  6. <a href="http://www.historicsheds.net/femminile-nike-kd-7-grigio-blu-schuhee">femminile nike kd 7 grigio blu</a> <a href="http://www.hochschulschrift.net/nike-free-4.0-flyknit-naranja-and-azul-kurpesc">nike free 4.0 flyknit naranja and azul</a> <a href="http://www.hotvape.net/asics-gel-kinsei-4-mosaic-herre-l%C3%B8b-sko-butyf">asics gel kinsei 4 mosaic herre l酶b sko</a> <a href="http://www.hungate.net/adidas-zx-flux-mujeres-oro-rush-scarpee">adidas zx flux mujeres oro rush</a> <a href="http://www.idreamtan.net/nike-air-presto-acquistare-online-schuhea">nike air presto acquistare online</a> <a href="http://www.ikkunatehdas.net/nike-shox-current-gris-orange-kurpesc">nike shox current gris orange</a>
    hotvape http://www.hotvape.net/

  7. <a href="http://www.curveshampton.com/air-jordan-retro-12-french-blu-2016-runningc">air jordan retro 12 french blu 2016</a> <a href="http://www.jcvindreau.com/hombres-adidas-zx-850-negro-blanco-zapatosj">hombres adidas zx 850 negro blanco</a> <a href="http://www.weinhefe.com/mujeres-nike-flyknit-air-max-corriendo-zapatos-glacier-ice-chaussuresa">mujeres nike flyknit air max corriendo zapatos glacier ice</a> <a href="http://www.fboagropec.com/nike-mercurial-superfly-silber-grau-foota">nike mercurial superfly silber grau</a> <a href="http://www.kikoyboy.com/nike-air-max-90-hot-punch-wei%C3%9F-rosa-runningd">nike air max 90 hot punch wei脽 rosa</a> <a href="http://www.giraprendi.com/andrew-wiggins-jersey-ebay-nflh">andrew wiggins jersey ebay</a>
    rxmedsuk http://www.rxmedsuk.com/

  8. avatar emailechelon

    <a href="http://www.swingergroup.com/nike-free-run-5.0-v2-orange-and-noir-no-flocking-trainersce">nike free run 5.0 v2 orange and noir no flocking</a> <a href="http://www.bluelakebooks.com/adidas-superstar-ii-grau-rot-schuhek">adidas superstar ii grau rot</a> <a href="http://www.lideresworld.com/nike-air-max-95-cuero-amarillo-rosado-scarpeg">nike air max 95 cuero amarillo rosado</a> <a href="http://www.navixstream.com/flyknit-lunar-3-gris-noir-knight-kurpesb">flyknit lunar 3 gris noir knight</a> <a href="http://www.clarinblogs.com/azul-and-verde-nike-roshe-zapatosk">azul and verde nike roshe</a> <a href="http://www.telecomcierge.com/nike-flyknit-lunar-1-sort-gr%C3%B8n-runningc">nike flyknit lunar 1 sort gr酶n</a>
    emailechelon http://www.emailechelon.com/

  9. avatar woistmeinhund

    <a href="http://www.swingergroup.com/nike-air-max-plus-tn-hyper-azul-zapatosk">nike air max plus tn hyper azul</a> <a href="http://www.bluelakebooks.com/nike-air-max-camo-and-rosa-runningc">nike air max camo and rosa</a> <a href="http://www.lideresworld.com/adidas-tubular-mujeres-olive-verde-zapatosj">adidas tubular mujeres olive verde</a> <a href="http://www.navixstream.com/nike-air-presto-bl%C3%A5-key-chaussuresa">nike air presto bl氓 key</a> <a href="http://www.clarinblogs.com/jordan-5-noir-tongue-2006-foota">jordan 5 noir tongue 2006</a> <a href="http://www.telecomcierge.com/nike-internationalist-damenn-gr%C3%A5-fuchsia-runningd">nike internationalist damenn gr氓 fuchsia</a>
    woistmeinhund http://www.woistmeinhund.com/

  10. avatar cliquism

    <a href="http://www.realchiyouth.com/nike-mercurial-vapor-blau-schuhel">nike mercurial vapor blau</a> <a href="http://www.djhomeimprove.com/adidas-pr%C3%B8dator-junior-gloves-skoe">adidas pr酶dator junior gloves</a> <a href="http://www.mybigrefund.com/asics-gel-lyte-5-sort-and-orange-footg">asics gel lyte 5 sort and orange</a> <a href="http://www.gamesiamfree.com/nike-free-3.0-v4-herre-bl%C3%A5-flame-sneakerd">nike free 3.0 v4 herre bl氓 flame</a> <a href="http://www.cavechezludo.com/nike-roshe-run-blum%C3%A4nner-wei%C3%9F-rosa-schuhee">nike roshe run blum盲nner wei脽 rosa</a> <a href="http://www.rxmedsuk.com/air-jordan-retro-1-b%C3%B8rn-bl%C3%A5-lyser%C3%B8d-footf">air jordan retro 1 b酶rn bl氓 lyser酶d</a>
    cliquism http://www.cliquism.com/

  11. avatar maplebeyond

    <a href="http://www.cardiachits.com/air-jordan-retro-3-violet-hommesthe-verte-chaussuresh">air jordan retro 3 violet hommesthe verte</a> <a href="http://www.zestchannel.com/nike-lebron-12-mujeres-p%C3%BArpura-rosado-zapatosp">nike lebron 12 mujeres p煤rpura rosado</a> <a href="http://www.eczacinim.com/nike-air-max-tailwind-7-black-silver-shoesi">nike air max tailwind 7 black silver</a> <a href="http://www.chilangorails.com/dam%C3%A4nner-air-jordan-retro-10-orangen-gold-schuhei">dam盲nner air jordan retro 10 orangen gold</a> <a href="http://www.mariusen.com/hombres-nike-roshe-run-high-naranja-gris-zapatosk">hombres nike roshe run high naranja gris</a> <a href="http://www.brittonoilco.com/kvinders-nike-flynit-air-max-lyser%C3%B8d-guld-skoi">kvinders nike flynit air max lyser酶d guld</a>
    maplebeyond http://www.maplebeyond.com/

  12. avatar sevenguard

    <a href="http://www.thebiarritz.com/polo-ralph-lauren-dip-dyed-linen-button-down-shirt-regular-fit-poloh">polo ralph lauren dip dyed linen button down shirt regular fit</a> <a href="http://www.voydnet.com/mens-nike-air-presto-purple-pink-shoesi">mens nike air presto purple pink</a> <a href="http://www.foneandlone.com/nike-air-max-90-premium-silver-white-shoesk">nike air max 90 premium silver white</a> <a href="http://www.roomwhiz.com/adidas-soccers-sko-gr%C3%B8nn-gull-obuvq">adidas soccers sko gr酶nn gull</a> <a href="http://www.riffsurfers.com/herre-nike-sb-stefan-janoski-max-alle-lilla-skoj">herre nike sb stefan janoski max alle lilla</a> <a href="http://www.davidmgaines.com/nike-air-max-zero-verde-rosa-scarpeq">nike air max zero verde rosa</a>
    sevenguard http://www.sevenguard.com/

  13. avatar delicouncil

    <a href="http://www.postthatass.com/m%C3%A4nner-nike-internationalist-grau-wei%C3%9F-schuhek">m盲nner nike internationalist grau wei脽</a> <a href="http://www.houseoftys.com/limited-demaryius-thomas-mens-jersey-denver-broncos-88-lights-out-grey-nfl-nflh">limited demaryius thomas mens jersey denver broncos 88 lights out grey nfl</a> <a href="http://www.amvdiplomados.com/nike-classic-cortez-premium-hvit-obuvi">nike classic cortez premium hvit</a> <a href="http://www.ybsimports.com/adidas-superstar-holographic-white-shoesj">adidas superstar holographic white</a> <a href="http://www.rochlockyer.com/adidas-tubular-doom-grey-primeknit-shoesl">adidas tubular doom grey primeknit</a> <a href="http://www.allsocialdata.com/men-long-sleeve-check-shirt-ralph-lauren-poloh">men long sleeve check shirt ralph lauren</a>
    delicouncil http://www.delicouncil.com/

  14. avatar thebiarritz

    <a href="http://www.jupickuplines.com/nike-zoom-pegasus-32-oransje-rosa-obuvk">nike zoom pegasus 32 oransje rosa</a> <a href="http://www.saleuggboot.com/mennns-air-jordan-2-gr%C3%A5-obuvi">mennns air jordan 2 gr氓</a> <a href="http://www.fragmanizletv.com/nike-air-max-tailwind-8-mujeres-verde-oro-zapatosk">nike air max tailwind 8 mujeres verde oro</a> <a href="http://www.swisshomeas.com/how-much-are-coach-shoes-worth-coachh">how much are coach shoes worth</a> <a href="http://www.marinersdiary.com/womens-nike-shox-turbo-21-blue-orange-shoesj">womens nike shox turbo 21 blue orange</a> <a href="http://www.bourseasie.com/kvinders-asics-gel-hyper-33-gul-s%C3%B8lv-skoq">kvinders asics gel hyper 33 gul s酶lv</a>
    [url=http://www.thebiarritz.com/]thebiarritz[/url]

  15. avatar brutalistmap

    <a href="http://www.preloxlady.com/hommes-new-balance-420-gris-schuheg">hommes new balance 420 gris</a> <a href="http://www.scalfarogroup.com/mujer-ralph-lauren-mesh-polo-pony-p%C3%BArpura-embroidery-poloz">mujer ralph lauren mesh polo pony p煤rpura embroidery</a> <a href="http://www.tubetotext.com/nike-kd-8-high-gr%C3%B8n-orange-chaussuresa">nike kd 8 high gr酶n orange</a> <a href="http://www.vapequalite.com/herre-nike-free-5.0-guld-lyser%C3%B8d-schuhed">herre nike free 5.0 guld lyser酶d</a> <a href="http://www.beylikduzufm.com/nike-air-max-bw-argento-verde-scarpea">nike air max bw argento verde</a> <a href="http://www.emmuscades.com/air-jordan-future-reflective-nero-and-bianca-kurpesf">air jordan future reflective nero and bianca</a>
    brutalistmap http://www.brutalistmap.com/

  16. avatar 都市女生

    感谢分享

  17. avatar 威客百科

    感觉还哦是挺麻烦的啊

  18. avatar 王语双

    送IP来了!

欢迎留言




用户登录

sitemap