- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我希望我的 Button 默认使用透明背景绘制,按下时使用深蓝色背景绘制,选中时使用浅蓝色背景绘制。我将按钮的背景设置为下面的选择器,并在单击按钮时调用 Button.setSelected(!Button.isSelected())
。按下状态正常工作,但 Button 在选中时使用透明背景绘制。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/tranpsshape" />
<item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/tranpsshape" />
<item android:state_pressed="true" android:drawable="@drawable/pressedbuttonshape" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/selectedshape" />
<item android:state_enabled="true" android:drawable="@drawable/tranpsshape" />
<item android:state_focused="true" android:drawable="@drawable/tranpsshape" />
<item android:state_selected="true" android:drawable="@drawable/selectedshape" />
<item android:drawable="@drawable/tranpsshape" />
</selector>
selectedshape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#A3DAF2"/>
</shape>
按下按钮形状.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#4ABDE8/>
</shape>
transpsshape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#00000000"/>
</shape>
最佳答案
During each state change, the state list is traversed top to bottom and the first item that matches the current state will be used—the selection is not based on the "best match," but simply the first item that meets the minimum criteria of the state.
所以你需要把state_selected
放在state_focused
上面。所以你的文件看起来像这样
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/tranpsshape" />
<item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/tranpsshape" />
<item android:state_pressed="true" android:drawable="@drawable/pressedbuttonshape" />
<item android:state_selected="true" android:drawable="@drawable/selectedshape" />
<item android:state_focused="true" android:state_enabled="true" android:drawable="@drawable/selectedshape" />
<item android:state_enabled="true" android:drawable="@drawable/tranpsshape" />
<item android:state_focused="true" android:drawable="@drawable/tranpsshape" />
<item android:drawable="@drawable/tranpsshape" />
</selector>
关于Android:如何在选中时为按钮绘制不同的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12320932/
嘿伙计们,我对java很陌生,我想知道是否有人可以解释为什么我在数组的开头得到一个随机空值,它是[null,r,b,o,e,r, t] 不知道为什么这样做!任何摆脱它的帮助都会很棒! public s
当我执行程序时 #include #include #include double exponential(double u); double exponential(double u) {
这个问题已经有答案了: 奥 git _a (17 个回答) 已关闭 7 年前。 我已经从 What does "Fatal error: Unexpectedly found nil while un
我正在开发一个债务跟踪应用程序,并且需要一个进度条,当当前债务下降时,进度会上升。我能想到的唯一方法是捏造周围的数字,使进度条 MAX 设置为 0,然后将起始债务更改为负数,如下所示 Progress
我知道当使用 ARC 并且你有一个 NSString 属性时,你可以像使用 MRC 一样执行 @property(nonatomic, copy)。但我想知道,在我将我的项目转换为 ARC 之后,我的
在 Xcode 6 Beta 2 上,我构建了一个带有 2 个 View Controller 的应用程序。 可以看到“Button”的 Action 是打开第二个ViewController。 但是
我正在使用 CreateFileA,我第一次调用它时,它按预期工作。但是当我第二次调用它时,它返回句柄 INVALID_HANDLE_VALUE。可能是什么问题呢?仅供引用,每次我需要检查我的 USB
我有一个被映射到生成器中的增强函数;然而,出于某种原因,tfa.image.rotate函数导致错误。 def customGenerator(input_file_paths, dims, data
我有查询并且有效 select *, id, from_unixtime(start_timestamp) from log limit 1; 这也很好用: select * from log lim
我有一个 FutureBuilder在我的具有常规结构的应用程序中: FutureBuilder( future: futureData(), builder: (context, snaps
所以我最近才接触到C++的SDL2,我做了这个非常简单的代码: int main(int argc, char** argv) { SDL_Event *event; bool done = fals
我正在打包一个非常简单的 redmine 插件 rpm,以供内部使用,但我遇到了“Package has no %description:”错误。 .spec 有一个描述,但我在 inet 上找不到任
call main() sub main() Dim scmd Set scmd = "c:\windows\system32\cscript.exe //nologo c:\s.vb
我正在使用以下代码在 Java 应用程序中使用 Git。我有一个有效的 key (一直使用它),并且这个特定的代码之前使用相同的 key 和 git 存储库对我有用,但现在我得到以下异常: inval
我有一个 Java 小程序,可以查询 Oracle 数据库中的数据。当从 IDE 内部运行时,它运行得很好。但是,当我将它作为嵌入网页中的小程序运行时,我在类加载器中收到“访问被拒绝”错误,并且我根本
我正在将一个 HTML 文件从 MainBundle 加载到 UIWebview 中,并想传入一个查询字符串,因为 HTML 文件检查 GET 参数 (?device=1) 以进行一些额外的计算。我还
我有一个包含多个项目的解决方案。每个项目都有自己的 nuspec 文件,其中一些项目相互引用 当我通过调用创建一个新包时 nuget pack MyLibrary.csproj -IncludeRef
我有一个测试文件和一个主模块文件,其中有一个我正在测试的函数。在测试文件的末尾,我有 unittest.main() 来运行单元测试。但是,当我运行测试文件时,控制台显示“未找到测试”,即使我的文件中
我在构建 docker 镜像时使用 dotnet:2.1-sdk 作为包。RUN dotnet restore 命令失败并出现以下错误: **error : Unable to load the se
这是一个简单的程序,只会执行 3 个子进程。每个都将创建一个锁,读取一个文本文件,并取消该锁的链接。如果正确执行,子进程将退出,并将其进程 ID 转换为 8 位。如果无法创建/取消链接锁,程序将尝试
我是一名优秀的程序员,十分优秀!