0

我对 NativeScript 很陌生。与 React Native 相比,我选择了它,因为我希望 100% 访问原生 API。我开始使用本机插件并阅读了一些类似本机库的教程 现在我正在尝试使用此插件FloatingActionButton遵循相同的原则

var app = require("application");
var platformModule = require("platform");
var fs = require("file-system");
var imageSource = require("image-source");

function creatingFab(args) {

    var fabMenu = new com.github.clans.fab.FloatingActionMenu(app.android.foregroundActivity);
    var fabButton = new com.github.clans.fab.FloatingActionButton(args.object.android);
    fabButton.setButtonSize(FloatingActionButton.SIZE_MINI);
    fabButton.setLabelText("Hello Button");
       
    //fabButton.setImageResource(imageSource.fromResource("logo"));
  
    fabMenu.addMenuButton(fabButton);
    fabMenu.hideMenuButton(false);
    
}

<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo" class="page">
  
    <Page.actionBar>
        <ActionBar title="My App" icon="" class="action-bar">
        </ActionBar>
    </Page.actionBar>
   
    <StackLayout class="p-20">
        <Label text="Tap the button" class="h1 text-center"/>
        <Button text="TAP" tap="{{ onTap }}" class="btn btn-primary btn-active"/>
        <Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
    </StackLayout>
    <android>
        <placeholder id="fab" tap="fabClick" class="fab-button" margin="15" creatingView="creatingFab"/>
   </android>
</Page>

模拟器中的错误

预先感谢您的帮助

4

1 回答 1

1

尝试基于此http://docs.nativescript.org/api-reference/classes/ application .androidapplication.html#foregroundactivity

var fabMenu = new com.github.clans.fab.FloatingActionMenu(app.AndroidApplication.foregroundActivity);
于 2017-03-05T21:13:23.030 回答