来自github.com/Clans/FloatingActionButton的NativeScript FloatingActionButton

时间:2017-03-05 20:51:20

标签: android nativescript angular2-nativescript nativescript-telerik-ui

我是NativeScript的新手。我选择它与React Native相比,因为我希望100%访问本机API。我开始玩原生插件并阅读一些像这样的教程native libraries 现在我尝试使用此插件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>

error in emulator

提前感谢您的帮助

1 个答案:

答案 0 :(得分:1)

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

var fabMenu = new com.github.clans.fab.FloatingActionMenu(app.AndroidApplication.foregroundActivity);