I am new to mvvmcross. In my xamarin android app, I want to change a buttons background image when the user clicks on it. I am not sure how this binding can be done. Can some one help me please.
You can bind any background image with DrawableId and DrawableName:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="DrawableId TheIntOfTheResource; Click SomeCommand" />
In SomeCommand you can change the id of TheIntOfTheResource which you bind to, so the image gets changed.
Related
My application is fairly simple, but I'm having issues with how best to setup the navigation/flow of my app using Shell and whether it's best to use Current.GoToAsync() or Current.Navigation.PushAsync() to go between the pages. (Or if there's a better way.)
My app starts off with a splash page, then to a login page, then to a tabbed page with 2 options. Each of those tabs show pages with list views where clicking on one of the items takes you to a detail page with a back button to go back to the list view page.
There's also a settings button in the header of the tabbed page that will display a flyout page of settings.
This crude drawing kinda shows what I mean.
Currently, in AppShell.xaml I have:
<Shell>
<ShellContent ContentTemplate="{DataTemplate views:SplashScreen}" />
</Shell>
After the user logs in they're taken to MainPage.xaml which is a TabbedPage setup like so:
<TabbedPage>
<views:DemoPageA Title="A" />
<views:DemoPageB Title="B" />
</TabbedPage>
Unfortunately, I'm always seeing a back button on every screen. I don't want users to go back to the splash screen or login screen, for example.
I'm just not sure if I need to somehow define my app differently in AppShell.xaml.cs or what. Any ideas are appreciated. Thanks!
You can add the following code to your page to hide the back button in the shell:
<Shell.BackButtonBehavior>
<BackButtonBehavior IsEnabled="False" IsVisible="False"/>
</Shell.BackButtonBehavior>
Here is related article about it: Back button behavior| Microsoft
I am adding iOS support for my already existing Xamarin Forms android app.
The toolbar items, navigational back arrow and the hamburger menu do not show on iOS:
While they work perfectly on Android:
The Application.MainPage is set to a Shell:
<Shell xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="app.MainPage"
FlyoutBackgroundColor="{StaticResource cBackgroundColorDark}"
Shell.TabBarTitleColor="{StaticResource cBackgroundColor}"
Shell.BackgroundColor="{StaticResource cBackgroundColor}">
<Shell.Resources>
<ResourceDictionary>
<vm:FlyoutVM x:Key="vm" x:Name="vm"/>
</ResourceDictionary>
</Shell.Resources>
<Shell.FlyoutHeader>
</Shell.FlyoutHeader>
<ShellContent Title="page1"
IsTabStop="True"
ContentTemplate="{DataTemplate views:Page1Page}"/>
...
<Shell.FlyoutContent>
</Shell.FlyoutContent>
<Shell.FlyoutFooter>
</Shell.FlyoutFooter>
</Shell>
The page with the toolbar items is simply:
<ContentPage>
<ContentPage.ToolbarItems>
<ToolbarItem Text="Example"
IconImageSource="Example.png"
Clicked="ExampleToolbarItem_Clicked"
/>
</ContentPage.ToolbarItems>
</ContentPage>
All navigation (hamburger menu, back button ect) and toolbar items can be tapped on iOS and work as intended - they just are not visible.
I do not understand why this does not work on iOS, any suggestions why this might be the case?
(I cannot find any styling that might be making it act differently. I have also tried displaying a toolbar with just text (no icons) and the problem persists)
I can provide more code if needed.
EDIT
I ended up creating a new Xamarin shell template project and moving everything over. That fixed the issue...
Most likely the image size for ios is incorrect. I use this https://appicon.co/#image-sets to create image set for ios.
I want to build a small chat as we all know from WhatsApp.
Currently I am able to display messages within a ListView.
<template>
<Page>
<ListView separatorColor="transparent" for="item in messages">
<v-template>
<GridLayout>
<TextView
height="auto"
editable="false"
:text="item.message"
/>
</GridLayout>
</v-template>
</ListView>
</Page>
</template>
My next step is to add a TextView with a Button at the end of the page. But here are coming my problems:
Which Layout component should I choose to position a TextView at the bottom of the page.
If I tab into my editable TextView the virtual keyboard overlaps my current page. Instead it should resize the whole page. How can I do this?
This is my current playground project: https://play.nativescript.org/?template=play-vue&id=F8lXkO
EDIT:
I found a way which works on Android using DockLayout:
https://play.nativescript.org/?template=play-vue&id=F8lXkO&v=3
Unfortunately this works only in the playground. Using the latest nativescript version on android is not working. If I tab on the TextView the layout breaks => https://github.com/sowinski/nativescript-vue-chat
Use GridLayout for the entire view. You can use this as a guide - https://github.com/Especializa/nativescript-whatsapp-template
Use this to better understand Nativescript layouts - https://www.nslayouts.com/
How can i make a webView in NativeScript fullscreen including the statusbar. Not hide the statusbar only but the webview behind the statusbar like do this cordova.
And how can i prevent the webview of scrolling/bouncing
Thank you
UPDATE:
What i mean with the statusbar/fullscreen and cordova is in cordova is the statusbar transparent and the web view fullscreen.
and the other question is about the bouncing, in cordova can i prevent the webview from bouncing with this in the config.xml
<preference name="webviewbounce" value="false" />
Update:
The solution for the bounce is this:
var webView = page.getViewById('webView');
webView.ios.scrollView.bounces = false
How can make the statusbar transparent?
The solution was on the end.
ios:
put this in the plist file to make the statusbar "transparent"
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
create a ios only file with this content to but the webview under the status bar
#webView{
margin-top: -20;
}
and add this to the page loaded function to prevent the webview of bouncing
if(page.ios){
webView.ios.scrollView.bounces = false
}
android:
is much simpler but this in the page wrapper of the webview to hide the titlebar
actionBarHidden="true"
i hope this helps anyone
I'm not following your question in regards to the statusbar and Cordova. However for the bouncing, the simplest option is to use this plugin which already has the native code for both iOS/android to remove the scroll bounce. See here: https://github.com/TheOriginalJosh/nativescript-swiss-army-knife#common-functions
If you can expand a bit more about what you want to do with the statusbar I can help there. I have a blog post detailing the android statusbar and navigation bar and a few things you can do natively with it in a few lines of code. https://bradmartin.net/2016/03/10/fullscreen-and-navigation-bar-color-in-a-nativescript-android-app/
I am running a android wear fullscreen app and after a certain time, the watch switches from app screen to the home screen (shows time). Is there any way to shop the switching. Thanks.
I assume by switches from app screen to home screen you mean that the watch goes to sleep / dims the screen.
Well you can prevent this by adding the android:keepScreenOn attribute to your layout-file.
For example:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">
...
</FrameLayout>
Alternatively you can add the flag in your Java-Code as well:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Note: Per default every wear-app will be closed as soon as the screen gets dimmed. A few weaks ago there has been a post on StackOverflow discussing the topic "Long Running Apps on Android Wear". You can find it here along with a pretty neat solution.