如何访问android';NativeScript中的s R对象?
我试图用Angular访问NativeScript中android的如何访问android';NativeScript中的s R对象?,nativescript,angular2-nativescript,nativescript-angular,Nativescript,Angular2 Nativescript,Nativescript Angular,我试图用Angular访问NativeScript中android的R对象,但没有成功。说明书上说要这样做: android.R.color.holo_purple 但是当我尝试从应用程序模块或tns核心模块/平台模块导入android变量时,我得到一个错误,即android对象上的R属性未定义。如何访问R?您不需要从应用程序模块导入android变量。默认情况下,它在运行时自动可用。要删除编译时错误属性不存在只需将名为android的变量声明为any 比如说 declare var andr
R
对象,但没有成功。说明书上说要这样做:
android.R.color.holo_purple
但是当我尝试从
应用程序
模块或tns核心模块/平台
模块导入android
变量时,我得到一个错误,即android
对象上的R
属性未定义。如何访问R
?您不需要从应用程序
模块导入android
变量。默认情况下,它在运行时自动可用。要删除编译时错误属性不存在
只需将名为android
的变量声明为any
比如说
declare var android:any;
export class AppComponent{
let holoPurple=android.R.color.holo_purple;
}
您不需要从
应用程序
模块导入android
变量。默认情况下,它在运行时自动可用。要删除编译时错误属性不存在
只需将名为android
的变量声明为any
比如说
declare var android:any;
export class AppComponent{
let holoPurple=android.R.color.holo_purple;
}
这里的
android
是android SDK的主要名称空间,而不是应用程序
模块中的android
属性
有关如何通过TypeScript访问本机SDK的说明,请参阅,或使用
android
中的说明,这里是android SDK的主命名空间,而不是应用程序模块中的android
属性
有关如何通过TypeScript访问本机SDK的说明,请参阅,或使用来自的说明。无法在最新的nativescript/angular中获得现有答案。我通过以下方式解决了这一问题:
创建了一个文件App_Resources/Android/values/keys.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="key_name">xxxxxx</string>
</resources>
然后抓住绳子
const context = app.android.context;
const res = context.getResources().getString(utils.ad.resources.getStringId('key_name'));
无法在最新的nativescript/angular中获取可用的现有答案。我通过以下方式解决了这一问题:
创建了一个文件App_Resources/Android/values/keys.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="key_name">xxxxxx</string>
</resources>
然后抓住绳子
const context = app.android.context;
const res = context.getResources().getString(utils.ad.resources.getStringId('key_name'));
我这样做了,但仍然无法访问android.R
。我可以在创建像这样的新对象时使用它让myObj=newandroid.native.sdk.class.Example
。那很好用。但是,如果我试图使用android.R.color.Red
而不使用new
关键字,将其传递给函数或将其设置为属性,则无法使用。请查看此注释,了解如何通过应用程序
模块访问资源文件,我这样做了,但仍然无法访问android.R
。我可以在创建像这样的新对象时使用它让myObj=newandroid.native.sdk.class.Example
。那很好用。但是,如果我试图使用android.R.color.Red
而不使用new
关键字,通过将其传递给函数或将其设置为属性,则无法使用。请查看此注释,了解如何通过应用程序
模块访问资源文件谢谢,我成功地从“@nativescript/core/application”从“@nativescript/core/utils”导入*作为utils
谢谢,我成功地将以下import*作为应用程序从“@nativescript/core/application”导入*作为utils从“@nativescript/core/utils”