如何在NativeScript中访问android的R对象? [英] How to access android's R object in NativeScript?
问题描述
我正在尝试使用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屋!