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

查看:86
本文介绍了如何在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 doesn't exists,只需将名为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天全站免登陆