how can i style xamarin calendarView. i've tried but it's not working. also it appears differently on different android API levels.
this is what i have tried so far
<CalendarView
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="#+id/calendarView1"
android:overScrollMode="always"
android:scrollbars="horizontal"
android:showWeekNumber="false"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
The Android.Widget.CalendarView class is a widget that consists of several subviews. The widget itself does not provide any real styling properties/methods. See the API docs:
Xamarin Android: https://developer.xamarin.com/api/type/Android.Widget.CalendarView/
Native Android:
https://developer.android.com/reference/android/widget/CalendarView.html
And it will look different on different versions of Android as the widget will use the theme/style of the Android version on which it is running.
You should be able to use styles and themes to style the CalendarView though. See this Android doc:
https://developer.android.com/guide/topics/ui/themes.html
As a very simple example, you could do this to use the Android built in Holo theme:
<CalendarView
...
android:theme="#android:style/Theme.Holo" />
And by following the guide linked above, you can create your own theme to use and even inherit from a built-in theme and just modify it. And setting a theme should keep it looking the same on all versions of Android.
Related
I am developing an app like Ola and Uber which will have navigation system and live tracking inside my Xamarin Forms app (For Android and iOS both platforms). So, can anyone please tell me the way to open the navigation map inside the app?
If you are trying develop an app like Ola/Uber which will have navigation system and live tracking inside the app, then you don't need to open the navigation map inside the app. You just need to display it on the page.
You can follow the official Xamarin.Forms documentation here, to add maps into your Xamarin Forms app. There's a full fledged map sample that you can also see to understand what needs to be done, but your XAML will look something like this:
<ContentPage ...
xmlns:maps="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps">
...
<maps:Map x:Name="map" />
...
</ContentPage>
The 3 dots indicate other controls you would like to add into the page and the layout that you have to put the Map control inside.
In fact you can also take a look at the sample code of several apps (RunAway, YellowClone, SmartHotel, BikeSharing, Movies, Evolve) in Javier Suarez's Good Looking UI curated collection.
Is there a way to define a Label in Xamarin Forms (XAML or code-behind) AppXYZ that can be updated from the Xamarin Android AppXYZ.Android: MainActivity.cs and AppXYZ.iOS:Main.cs? i.e. upon an event in Android (e.g. BlueTooth) set a short text in a common Forms elements? After viewing many example, no clarity yet. MessageCenter perhaps?
In Android Project: MainActivity.cs (for example):
FormsAppXYZ.LabelXYZ.Text = "Updated string";
If not possible, then proper way to do this with Xamarin Android Native ? appreciated since I'll have to mix in the label into a shared Xamarin Forms Tabbed GUI.
Depending on how much Bluetooth work you need to do, my first suggestion would be to use MessagingCenter as you have already alluded to.
The other obvious approach would be to use a third party plugin, as I don't believe Xamarin have released one. I am currently aware of these two:
https://github.com/aritchie/bluetoothle
https://github.com/xabre/xamarin-bluetooth-le
We currently have an app designed in Xamarin NativeUI (shared code and Xamarin.Android, Xamarin.UWP etc) are in the process deciding whether Xamain.Forms is mature enough to transition to.
One of my core concerns is that we have a very customized actionbar/toolbar that makes use of Android inbuilt handling of automatically moving items to overflow based on screen size, having overflow menus and submenus, custom controls in place of icons+text.
I have managed to get custom controls and hardcoded overflow items. But I'm not sure if the rest is possible without going native. And if we do need to go native I'm not sure how you would then use Xamarin.Forms and then have a Xamarin.Android ActionBar.
Another fun thinig to add to the equation is that we have to support Android 4.3 so that means using the support library actionbar.
Apologies, the question is a bit rambling but can be broken into 2 specifics:
1) With Xamarin.Forms can items move to or from overflow in toolbar automatically based on screen size available in similar fashion to Android native toolbar?
2) If using Xamarin.Forms can you use a toolbar defined in Xamarin.Android? How?
In addition to #Steve Chadbourne's answer, it's really important to know what page control are you using in PCL of your XF project, if you open the MainActivity.cs file in client android project, you can find by default it codes like this:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
As you can see, there is defined Toolbar which you can find in the Resources/layout folder in client Android project:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
This Toolbar is used by default within some page type control in XF, for example NavigationPage.
For native control of XF, I think it's possible that you didn't notice that Xamarin.Forms.ToolbarItem. It is also rendered like Toolbar and you can set the Order property to ToolbarItem to specify the item to be displayed on primary, secondary or default toolbar surfaces.
For custom renderers, it's possible that you can refer to this blog: Xamarin Forms - ContentPage with SearchBar in the Navigation bar.
Don't know which is the best choice for you, but I want to explain to your two questions. XF is like a UI toolkit, all controls it has are created based on the native SDK, means all controls are renderered as a matching native control so it can be used in native platform. So if a XF control is rendered as Toolbar in Android platform, the behavior should be the same as normal Toolbar in native Android, BUT like we customize the renderers, when the XF control is created, many properties are hard coded in its code, which may have effect the result here. If you meet such problem, I suggest to read the open source on Github.
For your last question:
If using Xamarin.Forms can you use a toolbar defined in Xamarin.Android? How?
You can either using custom renderers or directly modify the code in Toolbar.axml in native client Android project.
This should be possible in Xamarin Forms using a custom renderer.
You are one step ahead in that you understand what you want to do and how to do it in Xamarin Native.
Here is an overview on custom renderers.
Here is a link to a very basic navigation page custom renderer for Android. You should be able to expand it to include the native Android code you require.
Be aware that you probably need to override NavigationPageRenderer if you are using app compat to support earlier versions of Android.
Is it possible to mix iOS Storyboards and Xamarin Forms within one application? I have a bunch of views that are easier to be created in Forms, but some which are heavily customized so we would need to create some of them in native code.
I would like to use Storyboards to create the native parts, but can't seem to find a way to navigate from a Forms page to a Storyboard and vice versa.
I don't mind doing it from code, just need to know the direction to look into and if it's even possible.
You can create native views using the concept of Custom Renderers (see links below). The idea is that you create a Xamarin Forms Control that's shared between all platforms and which old common properties (like colors, general data etc), and do the native rendering on the iOS/Android/WP projects.
So, for your storyboard, you can create it usign Xamarin.iOS, and render using a Custom Renderer. The link posted by #GSerg in the comments have some information and examples, but you can take a closer look at the oficial documentation as well:
Introduction to Custom Renderers
Customizing Controls on Each Platform
Customizing Control Rendering in Xamarin.Forms (video)
Also, for more real world examples you can take a look at the Xamarin Forms XLabs project.
Thanks to Rafael Steil's answer. I looked at the links and a few more samples.
Notably:
Custom Renderer Map
Using Xamarin Forms alongside Storyboard
And I created a sample project to show the back-and-forth navigation between Xamarin Forms and pages created in Storyboards. You can find it over here:
Xamarin Forms Mixed with Native
I am working in xamarin pcl project , I am trying to keep sliding drawer in my pcl project but i dont know how to do that .
Are you using Xamarin.Forms?
If not, i would advice to use a framework like MvvmCross (https://github.com/MvvmCross/MvvmCross)
This would enable you to split the actual implementation of the drawer / hamburger menu into the different UI projects like iOS and Android(maybe WP8 too).
Since those platforms all behave differently, for example Android uses Fragments which are replaced inside the activity containing your navigation drawer, you should use a custom presenter to determine where you want the specific platform to navigate to. You can find more information on that topic here: http://slodge.blogspot.co.uk/2013/06/presenter-roundup.html