【问题标题】:NativeScript and D-pad navigationNativeScript 和方向键导航
【发布时间】:2018-09-28 18:13:26
【问题描述】:

如何使用原生 Android 方法(在此处描述:https://developer.android.com/training/tv/start/navigation 在“启用方向键导航”部分中,例如 nextFocusDown、nextFocusLeft 等)?我在我的代码中使用动态 id 分配。

这是一个例子:

<ListView class="list-group" for="(country,index) in countries" style="height:1250px">
<v-template>
    <FlexboxLayout flexDirection="row" class="list-group-item">
        <Image  :src="country.imageSrc" class="thumb img-circle" />
        <Button :id="'button'+index" @loaded="elementLoaded(index,$event)" text="Tap Me!" class="btn btn-primary btn-active" />
        <Label  :id="'label'+index" :text="index + country.name" style="color: red; width: 60%" />
    </FlexboxLayout>
</v-template>

export default {
    data() {
        return {
            countries: [
                {
                    name: "Australia",
                    imageSrc:
                    "https://play.nativescript.org/dist/assets/img/flags/au.png"
                },
                {
                    name: "Belgium",
                    imageSrc:
                    "https://play.nativescript.org/dist/assets/img/flags/be.png"
                }
            ]
        }
    },
    methods: {
        elementLoaded(index,args) {
            args.object.nextFocusDown("button"+(index+1))
            // How can I set native Android id to this element (like a Button) with help of NativeScript?
            // Also I need to set native Android attribute like "NextFocusDown" to this element (like a Button).
        },
    }
}

【问题讨论】:

    标签: android vue.js nativescript


    【解决方案1】:

    您始终可以通过访问原生视图属性来访问原生元素。

    // nativeView will be the native iOS / Android button and you are free to access any of it's native methods 
    args.object.nativeView 
    

    【讨论】:

      猜你喜欢
      • 2016-08-21
      • 2011-07-29
      • 2010-09-13
      • 2017-03-10
      • 2019-02-16
      • 1970-01-01
      • 2019-09-14
      • 1970-01-01
      • 2019-04-01
      相关资源
      最近更新 更多