首页 文章

如何防止TextField专注于NativeScript上的页面加载?

提问于
浏览
0

我've tried a couple different ways to get my text field to stop focusing on page load. The keyboard does not show when the page loads up but the field'的标签向上移动,就好像它处于焦点一样 . 我在link的顶部尝试了这个建议,但该领域仍然是焦点 . onPageLoad 我还通过Id检索了TextField,然后调用了 setFocusable(false) 但这完全阻止了我再次专注于该元素 . 并且android的 clearFocus 也没有做任何事情,因为该元素仍然试图集中注意力 . 如何让该领域停止专注于Android?它侧重于页面加载时的电子邮件地址字段 .

<Page 
    backgroundSpanUnderStatusBar="false" 
    backgroundColor="#222222" 
    loaded="onPageLoaded" 
    class="page" 
    actionBarHidden="true" 
    xmlns:Gradient="nativescript-gradient"
    xmlns:TIL="nativescript-textinputlayout">
    <GridLayout rows="*, auto, auto" columns="*">
        <GridLayout row="0" col="0" rows="auto, auto" columns="*" verticalAlignment="bottom" style="margin-bottom: 64dp;">
            <StackLayout row="0" col="0" style="margin-bottom: 16dp;">
                <Label class="h1 registration-app-title" horizontalAlignment="center" verticalAlignment="bottom" textWrap="true" text="Repeat"/>
            </StackLayout>
            <StackLayout row="1" col="0">
                <Label class="h3 registration-app-description" horizontalAlignment="center" verticalAlignment="bottom" textWrap="true" text="Save articles to your playlist and listen to them anywhere."/>
            </StackLayout>
        </GridLayout>
        <GridLayout row="1" col="0" rows="*, *, *, *" columns="*, *" class="registration-bottom">
            <StackLayout orientation="vertical" class="form" row="0" col="0" colSpan="2">
                        <TIL:TextInputLayout
                            class="text-input-layout"
                            hint="E-mail Address"
                            hintTextAppearance="StyledTIL"
                            >
                            <TextField 
                                id="text-field-email"
                                text="{{ email }}"
                                autocorrect="false" 
                                autocapitalizationType="none" 
                                keyboardType="email"
                                returnKeyType="next"/>
                        </TIL:TextInputLayout>

                        <TIL:TextInputLayout
                            class="text-input-layout"
                            hint="Password"
                            hintTextAppearance="StyledTIL"
                            marginBottom="30dp">
                            <TextField 
                                id="text-field-password"
                                text="{{ password }}"
                                secure="true"
                                autocapitalizationType="none"
                                returnKeyType="done"/>
                        </TIL:TextInputLayout>
            </StackLayout>
            <StackLayout orientation="horizontal" class="form" row="1" col="0" colSpan="2" style="width: 80%;">
                <Gradient:Gradient direction="to right" colors="#FF51A0FF, #FF3F2AFF" class="gradient" style="margin-right: 14;">
                    <Button class="btn btn-primary"
                            id="register-email"
                            text="Sign Up"
                            tap="register" />
                </Gradient:Gradient>
                <Gradient:Gradient direction="to right" colors="#FF51A0FF, #FF3F2AFF" class="gradient">
                    <Button class="btn btn-primary"
                            id="email"
                            text="Log In"
                            tap="authenticate"/>
                </Gradient:Gradient>
            </StackLayout>
            <StackLayout orientation="vertical" class="form" row="2" col="0" colSpan="2">
                        <Button class="btn btn-alternate"
                                id="facebook"
                                text="Connect with Facebook"
                                tap="authenticate"
                                textTransform="none"/>

                        <Button class="btn btn-alternate"
                                id="google"
                                text="Connect with Google"
                                tap="authenticate"
                                textTransform="none" />
            </StackLayout>
            <GridLayout row="3" col="0" colSpan="2" rows="*" columns="*">
                <Label class="h3 skip-step-label" 
                       id="anonymous"
                       row="0" 
                       col="0" 
                       text="Skip this step" 
                       tap="authenticate"/>
            </GridLayout>
        </GridLayout>
    </GridLayout>
</Page>

enter image description here

1 回答

  • 0

    尝试在页面的 navigatedTo 事件中从utils模块调用 dismissSoftInput .

    import { ad } as utils from "utils/utils";
    ad.dismissSoftInput();
    

    Update: 上面只会隐藏键盘,不会完全移除焦点 . 您总是需要另一个可以聚焦的视图,以便从TextField中移除焦点 . 这是一个如何做到这一点的例子,

    https://play.nativescript.org/?template=play-tsc&id=sgXKCB

相关问题