Nativescript: Creating a Button with no border or shadow

Created on 27 Mar 2017  路  7Comments  路  Source: NativeScript/NativeScript

I've got a NS app (w/o Angular) and trying to create a Button with no border or shadow - basically transparent.

I created a project tns create myApp --template tsc and then modified the "tap" button with css class definitions of

"btn btn-active"
"btn btn-primary btn-active"
"" (no class)

But can't get the border and shadow to disappear.

This is using the latest NS software + Android + Android emulator (dev on Windows 10).

question

Most helpful comment

Hi @erjdriver,
To remove the shadow of the button on Android you should set some borderWidth and to setup borderColor to transparent for the component as it has been shown in the example below:

XML

<StackLayout class="p-20">
        <Label text="Tap the button" class="h1 text-center"/>
        <Button text="TAP" tap="{{ onTap }}" class="btn btn-active"/>
        <Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
    </StackLayout>

CSS

.btn{
    border-color: transparent;
    border-width: 1;
}

All 7 comments

Hi @erjdriver,
To remove the shadow of the button on Android you should set some borderWidth and to setup borderColor to transparent for the component as it has been shown in the example below:

XML

<StackLayout class="p-20">
        <Label text="Tap the button" class="h1 text-center"/>
        <Button text="TAP" tap="{{ onTap }}" class="btn btn-active"/>
        <Label text="{{ message }}" class="h2 text-center" textWrap="true"/>
    </StackLayout>

CSS

.btn{
    border-color: transparent;
    border-width: 1;
}

Genius!

case closed.

Still, the native touch effect gets lost on android

.btn:active {
background-color: [your-color] ;
}
something like that ?

I've used :

.mybutton-class{
border-color: [same as background];
z-index: 0; to remove de shadow.
}

@tsonevn Without border-width: 1; it doesn't work... That makes no sense ...

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings