如何在 NativeScript 中访问 android 的 R 对象? [英] How to access android's R object in NativeScript?

查看:29
本文介绍了如何在 NativeScript 中访问 android 的 R 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Angular 在 NativeScript 中访问 android 的 R 对象,但我没有成功.此处 的说明说要这样做:

I am trying to access android's R object in NativeScript with Angular but I haven't had any success. The instructions here say to do it like this:

android.R.color.holo_purple

但是当我尝试从 application 模块或 tns-core-modules/platform 模块导入 android 变量时,我得到一个android 对象上的 R 属性未定义的错误.如何访问 R?

But when I try to import the android variable from the application module or the tns-core-modules/platform module I get an error that the R property on the android object is undefined. How do I get access to R?

推荐答案

你不需要从 application 模块导入 android 变量.默认情况下,它在运行时自动可用.删除编译时错误 property does not exist 只需将名为 android 的变量声明为 any.

you don't need to import android variable from application module. it is automatically available by default at runtime. to remove compile time error property doesn't exists just declare the variable named android to any.

例如.

declare var android:any;
export class AppComponent{
  let holoPurple=android.R.color.holo_purple;
}

这篇关于如何在 NativeScript 中访问 android 的 R 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆