Android开发设置Button的background

来源:互联网 发布:什么软件挣钱快好提现 编辑:程序博客网 时间:2024/06/01 07:26

      前几日用到 Button的background属性,按部就班的做的,但运行结果死活都不对,在网上搜的结果也都大同小异。本人英语很差,但没办法,只能求助于Android开发文档了,下面把解决了我问题的一段话粘过来。

       During each state change, the state list is traversed top to bottom and the first item thatmatches the current state is used—the selection isnot based on the "bestmatch," but simply the first item that meets the minimum criteria of the state.

      这段话的大概意思是:在状态改变时,会在状态列表中从上到下的遍历,选一个能满足最低标准的状态,而不是去匹配最佳的。

      举个例子,在状态列表中有两个状态:state_enabled="true",state_pressed="true"。state_enabled在前。这样当按下按钮时匹配到的状态理应是state_pressed,但实际上匹配到的是state_enabled。为什么呢?因为遍历状态列表时首先判断的是state_enabled是否为true,显然按钮此时可用,匹配成功,这样就不会再往下去匹配了。所以不管我怎么按下按钮背景图片始终不变。

0 0
原创粉丝点击