android - NativeScript TextView :textTransform can't update

标签 android nativescript nativescript-vue

我将 NativeScript 与 Vue.js 结合使用。我在 TextView 中有一些文本,我试图通过使用 textTransform 属性将该文本从“无”更改为“大写”。 这是我的示例代码和 here来自ns playground

<template>
    <Page class="page">
        <ActionBar title="Home" class="action-bar" />
        <ScrollView>
            <StackLayout>
                <TextView editable="false" :fontSize="textFontSize"
                    :textTransform="upperCaseText">
                    <FormattedString>
                        <Span text="This is a text view that uses attributed text. You can use text attributes such as " />
                    </FormattedString>
                </TextView>
                <Button text="Make uppercase" @tap="toUpperCase" />
            </StackLayout>
        </ScrollView>
    </Page>
</template>
<script>
    export default {
        data() {
            return {
                upperCaseText: "none",
                textFontSize: 20
            };
        },
        methods: {
            toUpperCase() {
                this.upperCaseText = "uppercase";
                this.textFontSize = 67;
            }
        }
    };
</script>

当我单击Make uppercase 按钮时,属性upperCaseText 已从“无”更改“大写”,但 TextView 未注册此更改,并且显示的文本未更改。

我试图从 ns“dom”更改 upperCaseText 属性,尝试以某种方式触发 TextView 上的事件并“告诉“有些事情发生了变化,但没有成功。

有趣的是,当我尝试更改文本的fontSize 时。没有问题,fontSize 明显改变了,但是 textTransform 没有。

为什么会这样?为什么 fontSize 没有问题,而 textTransform 却不起作用?以及如何让它发挥作用?

最佳答案

由于 Android 的限制,更新文本转换属性不会对已在 TextField/TextView 上设置的文本产生任何影响。更多信息可以在相关的 Github issue 中找到.

TextField & TextView (Android)

Setting text-transform property on these controls will not change the text inside them. In case you want to transform the text you should do it before setting it to text property.

我不确定您为什么将 TextView 设置为只读 (editable="false"),如果您不想要可编辑的 TextView,那么您可以简单地使用一个应该支持动态更新文本转换的标签。

关于android - NativeScript TextView :textTransform can't update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56516387/

相关文章:

android - 占位符和图像的不同比例类型

android - 如何导入声音并在Android中使用它们?

android - 找不到 recyclerview-v7.jar (com.android.support :recyclerview-v7:28. 0.0)

NativeScript-Vue - 从外部组件导航

Nativescript-vue 类似web的简单选择组件

java - 位图工厂给出空位图

android - ArrayOutOfBounds 将 addHeaderView() 与 EndlessAdapter 一起使用时

ios - native 脚本警告 : Cannot find a valid certificate or provisioning profile for the iOS platform

javascript - 下载 JS 文件并使用 NativeScript 作为后台服务运行

javascript - 为什么 toLocaleString() 方法不起作用?