我對NativeScript很陌生。我選擇它與React Native相比,因爲我想100%地訪問本機API。我開始與本地插件玩耍,閱讀一些教程這樣一個native libraries 現在我試圖遵循同樣的原則有了這個插件FloatingActionButton來自github.com/Clans/FloatingActionButton的NativeScript 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>
預先感謝您的幫助
很酷的東西 - 如果你想使用的東西使用了android已經寫原生FAB小部件有這個插件https://github.com/bradmartin/nativescript-floatingactionbutton,但我瞭解你正在採取的學習方法。這是我在一年前寫這篇文章時開始的地方:)所以繼續做你正在做的事情,你會越來越欣賞本地文字。 @MarekMaszay下面的答案可能會有所幫助。如果沒有,你正在使用的Android庫可能會要求你傳遞一個圖像,它看起來像你註釋了設置圖像的行。 –
@BradMartin,我是你博客的粉絲。感謝像你這樣的人,這只是我第二天的本地文字,但我學到了很多東西。我一定會使用你的插件github.com/bradmartin/nativescript-floatingactionbutton。我已經看過它了。我只是想看看我是否可以輕鬆地連接到任何本機插件。我非常驚訝於NativeScript可以做些什麼。我只需要把它推到極限,看看我能走多遠:)。 – Selom
我已取消註釋該行並遵循@MarekMaszay的建議,但仍無法使用。我會繼續研究它。 – Selom