how to remove the auto padding in nativescript android actionbar? - nativescript

I tried to add two colors with full width in nativescript android. But it always takes extra padding. Below is my code-
<ActionBar class="p-l-0 m-l-0" backgroundColor="#007FA3">
<GridLayout rows="auto,auto" columns="*">
<StackLayout class="p-2" row="0" style="background-color: #F29F03;" horizontalAlignment="left">
<Label class="action-label p-2" width="200%" text=" Please wait" fontSize="12" color="white" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
<StackLayout orientation="horizontal" row="1">
<label textAlignment="center" text=" " class="fas" row="1" color="white"></label>
<Label text="PageTitle" fontSize="22" color="white" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
</GridLayout>
</ActionBar>
How to remove the extra margin before orange label?

If you're using a later version of Theme then you may need to increase the css specificity, such as:
.ns-root ActionBar.actionbar {
margin: 0;
padding: 0;
}
And in your xml file,
<ActionBar class="actionbar" backgroundColor="#007FA3">
...

Related

RadListView with tkGroupTemplate with inner content scroll horizontal

Tell us about the problem
I am trying to horizontally set the content that is grouped with the function of but is not possible, because all content is horizontal.
Which platform(s) does your issue occur on?
Both
Please tell us how to recreate the issue in as much detail as possible.
<RadListView
[items]="dataItems"
#productsListView
[groupingFunction]="grouping"
>
<ng-template tkListItemTemplate let-item="item">
<StackLayout orientation="horizontal" width="100%">
<MDCardView width="100" height="100">
<Image stretch="aspectFill" [src]="item.image"></Image>
</MDCardView>
</StackLayout>
</ng-template>
<ng-template tkGroupTemplate let-category="category">
<GridLayout columns="*, auto" ios:height="50">
<Label
col="0"
style="font-weight: bold; font-size: 24"
[text]="category"
></Label>
<Label
col="1"
style="font-size: 12; color: gray;"
text="Ver más"
></Label>
</GridLayout>
</ng-template>
<ListViewGridLayout
tkListViewLayout
itemHeight="100"
scrollDirection="Horizontal"
></ListViewGridLayout>
</RadListView>
Try ScrollView within tkGroupTemplate
<ng-template tkGroupTemplate let-category="category">
<GridLayout>
<ScrollView orientation="horizontal" scrollBarIndicatorVisible="false">
<Label class="m-5 h2" [text]="category"></Label>
</ScrollView>
</GridLayout>
</ng-template>
Playground Sample

StackLayout's vertical alignment

I'm trying to put a button at the bottom of a StackLayout and it's not working.
I don't know what I'm doing wrong!
Here's my template:
<Page actionBarHidden="true">
<GridLayout rows="*, *, *, *" columns="*">
<StackLayout horizontalAlignment="center"
verticalAlignment="center">
<Label text="My Account" id="login-label"/>
</StackLayout>
<CardView row="1" class="cardStyle" margin="10"
elevation="40"
radius="4"
verticalAlignment="center"
horizontalAlignment="center"
rowSpan="2"
id="login-box">
<StackLayout id="form-container">
<TextField hint="Login"/>
<TextField hint="Password"/>
<Label text="Forgot password?" horizontalAlignment="right"/>
<Button text="Button" #tap="loginButton()" verticalAlignment="bottom"/>
</StackLayout>
</CardView>
</GridLayout>
</Page>
Thank you!
StackLayout do not support that by its design. It is used to just stack the child elements one after another in given orientation, you can't have mixed output - few child elements at top and few at bottom or center.
Use Grid / Dock layout in order to dock an element at bottom.

In Nativescript how can I achieve a vertically aligned label text using StackLayout

I need something like this:
But this is what I have at the moment:
.rotate {
transform: rotate(-90deg);
font-size: 16px;
color: #FFFFFF;
}
This is my code:
<StackLayout backgroundColor="#3C414B" width="12%" height="100%" horizontalAlignment="center" verticalAlignment="center" (tap)="openDrawer('Right')">
<StackLayout class="rotate" orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label width="100%" class="" text="New Category" textwrap="false"></Label>
</StackLayout>
</StackLayout>
You will have to set the height explicitly to the width of the element, transform doesn't take care of that by default.
Or you may even consider using an image, here is a related thread from Forums.
It looks like you rotate inner <StackLayout class="rotate" ...>, but it still get width limit of outer <StackLayout width="12%" ...>
Try so:
<StackLayout class="rotate" backgroundColor="#3C414B" width="100%" height="12%" horizontalAlignment="center" verticalAlignment="center">
<StackLayout orientation="horizontal">
<Label class="fa" style="margin-right: 10px" text=""></Label>
<Label text="New Category" textwrap="false" backgroundColor="yellow"></Label>
</StackLayout>
</StackLayout>
Or try to find solution with other layout type. For example, AbsoluteLayout

Nativescript inner StackLayout

Hello everyone I'm trying to make inner StackLayouts but the second one comes to top of first one so that I can't see the second StackLayout should I handle with css if it is how or is there an other way
Here is my code
<StackLayout orientation="horizontal">
<StackLayout width="500">
<GridLayout columns="50, *" rows="*" width="500" height="50"
verticalAlignment="top">
<Label text="Name" row="0" col="0" backgroundColor="red">
</Label>
<Label text="Fol" row="0" col="1" class="alignRight"
backgroundColor="blue"></Label>
</GridLayout>
</StackLayout>
<StackLayout orientation="horizontal" width="500" height="180">
<Image src="http://lorempixel.com/400/200" width="500" left="10"
top="30">
</Image>
</StackLayout>
</StackLayout>
Thank you
At first I would delete the widths to see how the page is displayed. 500 is a very big value. Only large tablets can support that.
As an example at first I would try this :
<GridLayout columns="auto, auto">
<GridLayout col="0" columns="50, *" rows="*" verticalAlignment="top">
<Label text="Name" row="0" col="0" backgroundColor="red">
</Label>
<Label text="Fol" row="0" col="1" class="alignRight"
backgroundColor="blue"></Label>
</GridLayout>
<Image col="1" src="http://lorempixel.com/400/200" left="10" op="30">
</Image>
</GridLayout>
After you see the two parts align horizontally you can start tweaking the widths

Image button Nativescript and Angular

I need to create an Image button which includes a custom image and a label in {N} + Angular.
Something like this:
Here's my code. I'm using the stack layout inside the grid layout. I can't see the label below the image.
<GridLayout columns="*,*" rows="*,*,*,*,*,*" width="400" height="400">
<StackLayout class=" btn-sq-lg " col="0" row="0" (tap)="gotoSRTPage()">
<Image col="0" row ="1" src="res://ic_briefcase" > </Image>
<Label class= "label" textWrap="true" col="0" row="2" text="SRT" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
<StackLayout class=" btn-sq-lg " col="1" row="0" (tap)="">
<Image col="1" row ="1" src="res://ic_blog" > </Image>
<Label class= "label" col="1" row="2" text="SRT" horizontalAlignment="center" verticalAlignment="center"</Label>
</StackLayout>
<StackLayout class=" btn-sq-lg " col="0" row="3" (tap)="">
<Image col="0" row ="4" src="res://ic_reminder" > </Image>
<Label class= "label" textWrap="true" col="0" row="5" text="SRT" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
<StackLayout class=" btn-sq-lg " col="1" row="3" (tap)="">
<Image col="1" row ="4" src="res://ic_announcement" > </Image>
<Label class="label" textWrap="true" col="1" row="5" text="SRT" horizontalAlignment="center" verticalAlignment="center"></Label>
</StackLayout>
</GridLayout>
css file:
.btn-sq-lg {
background-color: white;
}
.label {
text-align: center;
color:#00caab;
}
So far i haven't found a straight-forward way to do it but i have a work around
You can try the following
some.component.html
<StackLayout class="btn-img" orientation="horizontal" padding="5" (tap)="onTappedFun()" >
<Image src="res://facebook" width="10%" height="100%" marginRight="10"></Image>
<Label text="Login via Facebook" verticalAlignment="center"></Label>
</StackLayout>
some.component.css
.btn-img{
border-radius: 5;
border-width: 1;
color: white;
margin: 10;
font-size: 22;
border-color: #2b3c6a;
background-color: #3B5997;
}
some.component.ts
onTappedFun(){
console.log("Hey i was tapped");
}
Result
Using only CSS you can reach the desired style:
.my-button {
color: #395469;
background-color: #FFFFFF;
background-image: url("https://play.nativescript.org/dist/assets/img/NativeScript_logo.png");
background-repeat: no-repeat;
background-position: 35 28;
background-size: 60 60;
border-width: 2;
border-color: #395469;
border-radius: 28;
height: 56;
font-size: 16;
}
In the XML apply the style class:
<Button text="I like NativeScript" class="my-button"></Button>
You can try this :
<GridLayout columns="*,*" rows="*,*" width="400" height="400">
<StackLayout row="0" col="0" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name1" height="20%"></Label>
</StackLayout>
<StackLayout row="0" col="1" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name2" height="20%"></Label>
</StackLayout>
<StackLayout row="1" col="0" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name3" height="20%"></Label>
</StackLayout>
<StackLayout row="1" col="1" orientation="vertical">
<Image src="~/images/star-empty.png" height="80%"></Image>
<Label class="label" textWrap="true" text="Button Name4" height="20%"></Label>
</StackLayout>
</GridLayout>
<Button>
<Image res="<path>"></Image>
<Label text="{{text}}"></Label>
</Button>
--EDIT--
Why have I been downvoted for this? It answers the question that was asked?

Resources