android - NativeScript 和方向键导航
问题描述
如何使用原生 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).
},
}
}
解决方案
You can always access the native element by accessing the native view property.
// nativeView will be the native iOS / Android button and you are free to access any of it's native methods
args.object.nativeView
推荐阅读
- python - 地图不显示
- python - 如何传递 3 个参数作为 Python 中的一个数组?
- rest - 从 SharePoint Online 删除文件,为什么总是产生错误 403?
- r - 在模拟之前是否有一个 R 函数可以将两个变量合并为一个?
- php - 爆炸php数组端点
- php - 如何读取excel文件并提取数组中列的值
- javascript - nodejs护照BasicStrategy未经授权
- localhost - 如何解决“本地主机拒绝连接”错误?
- asp.net - 在 Firefox 中显示 NaN 的剩余天数,Chrome 完美运行 - 代码日志
- r - 如何在另一个向量 ifelse 上递归地评估条件向量