简体   繁体   English

我可以使用Android中的“辅助功能”获取和设置textView的textcolor

[英]Can I get and set textcolor of a textView using Accessibility in Android

I am developing an app for color-blind, I want to know if I can change the textcolor of a textView using Accessibility in Android. 我正在开发一个色盲应用程序,我想知道我是否可以使用Android中的Accessibility更改textView的文本颜色。 Also, I would like to change the textSize using Accessibility. 另外,我想使用辅助功能更改textSize。

Can I do these things?, If yes, how? 我可以做这些事吗?如果是的话,怎么样?

No, you cannot. 你不能。 You don't get the actual TextView of the represented text. 您没有获得所代表文本的实际TextView。 You get access to an AccessibilityNodeInfo. 您可以访问AccessibilityNodeInfo。 The accessibility APIs don't provide this information. 辅助功能API不提供此信息。 You could do some hacky things if you also controlled the app content, but if you want something that will work universally over all applications, you simply can't do this. 如果你还控制了应用程序内容,你可以做一些hacky事情,但是如果你想要一些普遍适用于所有应用程序的东西,你就是不能这样做。

You could guess at the size of the text by checking the size of the TextView. 您可以通过检查TextView的大小来猜测文本的大小。 The size of the TextView is passed to you through TextView的大小将传递给您

aNodeInfo.getBoundsInScreen(resultBounds);

Although, this is very hacky and not reliable. 虽然,这非常hacky,不可靠。 The size of the view and the text size don't have to be the same, or even remotely related. 视图的大小和文本大小不必相同,甚至是远程相关的。 Though generally for single line TextViews there will be a tight correlation. 虽然通常对于单行TextViews会有紧密的相关性。 Notably, you cannot detect when a TextView is single line :) 值得注意的是,你无法检测TextView何时是单行:)

For text size of the textview you can provide size in terms of 'sp' instead of 'dp'. 对于textview的文本大小,您可以使用'sp'而不是'dp'来提供大小。 Framework will automatically take care of size. 框架将自动处理大小。

And for color above answer given by @rakesh can be one of the answers. 对于@rakesh给出的上述答案的颜色可以是答案之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM