首页 \ 问答 \ 如何在Android中更改XML中按钮的textColor?(How to change textColor of a button from XML in Android?)

如何在Android中更改XML中按钮的textColor?(How to change textColor of a button from XML in Android?)

我正在使用selector来更改按钮在不同状态下的背景可绘制(聚焦,按下,正常)。 有没有办法改变文字的颜色呢? 我想为各种按钮状态提供各种文本颜色,但是我想从xml中完成。 这可能吗?


I am using a selector to change the background drawable of the button in different states (focused, pressed, normal). Is there any way to change the text color too? I want to provide various text colors for various button states, but I want to do it from the xml. Is this possible?


原文:https://stackoverflow.com/questions/6860115
更新时间:2023-10-21 16:10

最满意答案

我相信以下是我的问题的最佳答案之一。 我已经将@ 0andriy提供的链接用于内核源代码中的现有示例。

转换带符号的16位值进行传输

s16 src = -5;
u8 dst[2];
__be16 tx_buf;
*(__be16*)dst = cpu_to_be16(src);

转换多个带符号的16位值进行传输

s16 src[2] = {-5,-2};
u8 dst[4];
s16* psrc = src;
u8* pdst = dst;
int len = sizeof(src);

for ( ; len > 1; len -= 2) {
    *(__be16 *)pdst = cpu_to_be16p(psrc++);
    pdst += 2;
}

快速免责声明,我仍然需要检查此代码是否正确/编译。

总的来说,我对复制和转换多个值的字节序的解决方案有点不满意,因为它很容易出现拼写错误并且可以很容易地实现到宏中。


I believe the following is one of the best answers to my question. I have used the links provided by @0andriy to existing examples in the kernel source code.

Converting a signed 16-bit value for transmitting

s16 src = -5;
u8 dst[2];
__be16 tx_buf;
*(__be16*)dst = cpu_to_be16(src);

Converting multiple signed 16-bit values for transmitting

s16 src[2] = {-5,-2};
u8 dst[4];
s16* psrc = src;
u8* pdst = dst;
int len = sizeof(src);

for ( ; len > 1; len -= 2) {
    *(__be16 *)pdst = cpu_to_be16p(psrc++);
    pdst += 2;
}

A quick disclaimer, I still need to check if this code is correct / compiles.

Overall, I'm a bit unsatisfied with the solution for copying and converting the endianness of multiple values since it is prone to typos and could easily be implemented into a macro.

相关问答

更多
  • 如果你的意思是“标准玩家硬件”的PC,那么你不必担心字节码,因为它在x86 / x64上总是很小端的。 但是如果你想把这个项目移植到其他架构上,那么你应该独立设计它的字节顺序。 If you mean a PC by "standard gamer hardware", then you don't have to worry about endianness as it will always be little endian on x86/x64. But if you want to port the ...
  • 按照C标准,编译器可以自由地以任何随意的方式存储位字段。 你不能对这些位的分配进行任何假设。 这里只是一些没有被C标准指定的位域相关的东西: 未指定的行为 分配用于保持位字段的可寻址存储单元的对齐(6.7.2.1)。 实现定义的行为 位域是否可以跨越存储单元边界(6.7.2.1)。 单位内位位的分配顺序(6.7.2.1)。 大/小的endian当然也是实现定义的。 这意味着您的结构可以通过以下方式分配(假设16位int): PADDING : 8 f1 : 1 f2 : 3 f3 : 4 or PADD ...
  • 没有任何字节序问题。 只要StupidApi不涉及通过网络发送或平台之间的序列化,那么根本就没有字节序问题。 There isn't any endianness problem. As long as StupidApi doesn't involve sending it over a network or serialization between platforms, then there's no endianness issue at all.
  • 我相信以下是我的问题的最佳答案之一。 我已经将@ 0andriy提供的链接用于内核源代码中的现有示例。 转换带符号的16位值进行传输 s16 src = -5; u8 dst[2]; __be16 tx_buf; *(__be16*)dst = cpu_to_be16(src); 转换多个带符号的16位值进行传输 s16 src[2] = {-5,-2}; u8 dst[4]; s16* psrc = src; u8* pdst = dst; int len = sizeof(src); for ( ; ...
  • 在查看IECType.php后 ,我注意到它将PHP类型转换为IEC 1131类型。 Little endian首先存储最低有效字节。 你的描述会让我觉得系统使用的是16位地址。 如果您查看wiki上的endianess函数中引用的Endianess,那么您会在Little-endian下看到一个名为Atomic元素大小为16位的小节。 一个地址包含两个字节(CCDD)和(AABB)。 持有(CCDD)的地址最不重要,因此它将首先列出。 如果你在8位系统中工作,那么每个字节将被排序(DDCCBBAA),因为 ...
  • 我只是手动将字节复制到临时双,然后返回。 在C(我认为是C ++)中,可以将任何指针转换为char * ; 这是别名的显式权限之一(在标准草案n1570,参数6.5 / 7中),正如我在其中一篇评论中提到的那样。 为了完成接近硬件的任何事情,这个例外是绝对必要的; 包括通过网络收到的反转字节:-)。 没有标准的编译时间方式来确定这是否是必要的,这是一个遗憾; 如果你想避免分支,如果你处理大量数据可能是一个好主意,你应该查找编译器的专有定义文档,以便你可以在编译时选择正确的代码分支。 例如,gcc将__FLO ...
  • 问题是系统的字节顺序......和文件的字节顺序是不同的。 不,他们是一样的。 看看数据。 最低有效字节在开始时。 这是小端,这是英特尔的字节顺序。 ( 不是 'Windows字节顺序',除了特定平台外,AFAIK不存在)。 问题是文件和系统的endianness-ness是little-endian,但RandomAccessFile是big-endian。 在Java中解决这个问题的方法是通过NIO和ByteBuffer ,使用本机字节顺序而不是默认值。 the problem is that the ...
  • 传递给内核的参数保证具有正确的字节序(因此所有typedefs cl_int等),但缓冲区不是这种情况。 这是有道理的,因为缓冲区的内容对于OpenCL来说是完全不透明的:只有用户知道如何理解内部的内容。 因此,用户有责任在进行计算之前执行潜在的字节序转换(可能通过启动专用内核)。 换一种说法: __kernel void vecAdd(__global float * c, ..) 这里, c的值保证是正确的字节顺序(指针的字节本身是正确的设备顺序),但c指向的字节是用户在主机上设置它们的顺序。 为什么 ...
  • 要检查endianess,您需要发送至少两个字节的值。 你不能仅仅通过发送单个字节来检查,因为在那一点上已经为你排列了比特级的endianess。 因此,对于字节交换 (如果需要),如果您尝试使用特定于端点的规则打包各个位,例如在C中使用位域时,端点只是重要的。 如果您的问题与您自己在WebSocket有效负载中携带的消息有关,通常的过程是自己选择一个字节顺序,然后执行任何打包或解包,您需要做的是从本机字节顺序转换为您的首选字节顺序。 我所知道的大多数协议都使用big-endian,即“网络秩序”。 所以, ...
  • 好吧,除了endianness,你还有非IEEE-754格式的潜力,但这是罕见的。 如果你可以假设IEEE-754二进制,那么它几乎肯定会使用与整数相同的字节序,但你可以通过使用一个2的负幂(例如-1.0)的浮点值来检查,它将具有非-zero MSbyte(包含符号和指数的一部分)和零LSbyte(包含最不重要的尾数位)。 float floatNumber = -1.0; uint8_t *numPtr = (uint8_t*)&floatNumber; if (numPtr[0] == 0) { e ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)