Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 47efb7a

Browse files
authored
New sample. (#674)
1 parent b4c1b55 commit 47efb7a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+940
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Xamarin.Forms - TabbedPage with vector graphic tab icons
3+
description: "This sample demonstrates how to display SVG files as tab icons in a Xamarin.Forms TabbedPage (navigation)"
4+
page_type: sample
5+
languages:
6+
- csharp
7+
products:
8+
- xamarin
9+
urlFragment: navigation-tabbedpagewithsvgtabicons
10+
---
11+
# Xamarin.Forms TabbedPage with SVG tab icons
12+
13+
This sample demonstrates how to display Scalable Vector Graphic (SVG) files as tab icons in a Xamarin.Forms [`TabbedPage`](xref:Xamarin.Forms.TabbedPage).
14+
15+
For more information about this sample, see [Xamarin.Forms TabbedPage](https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/navigation/tabbed-page).
16+
17+
![TabbedPage application screenshot](Screenshots/01All.png "TabbedPage application screenshot")
98.8 KB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Any raw assets you want to be deployed with your application can be placed in
2+
this directory (and child directories) and given a Build Action of "AndroidAsset".
3+
4+
These files will be deployed with your package and will be accessible using Android's
5+
AssetManager, like this:
6+
7+
public class ReadAsset : Activity
8+
{
9+
protected override void OnCreate (Bundle bundle)
10+
{
11+
base.OnCreate (bundle);
12+
13+
InputStream input = Assets.Open ("my_asset.txt");
14+
}
15+
}
16+
17+
Additionally, some Android functions will automatically load asset files:
18+
19+
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Android.App;
2+
using Android.Content.PM;
3+
using Android.OS;
4+
5+
namespace TabbedPageSVGIcons.Droid
6+
{
7+
[Activity(Label = "TabbedPageSVGIcons", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize)]
8+
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
9+
{
10+
protected override void OnCreate(Bundle savedInstanceState)
11+
{
12+
TabLayoutResource = Resource.Layout.Tabbar;
13+
ToolbarResource = Resource.Layout.Toolbar;
14+
15+
base.OnCreate(savedInstanceState);
16+
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
17+
LoadApplication(new App());
18+
}
19+
}
20+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.tabbedpagesvgicons">
3+
<uses-sdk android:minSdkVersion="21" />
4+
<application android:label="TabbedPageSVGIcons.Android" android:theme="@style/MainTheme"></application>
5+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
6+
</manifest>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
using Android.App;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("TabbedPageSVGIcons.Android")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("TabbedPageSVGIcons.Android")]
14+
[assembly: AssemblyCopyright("Copyright © 2014")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
[assembly: ComVisible(false)]
18+
19+
// Version information for an assembly consists of the following four values:
20+
//
21+
// Major Version
22+
// Minor Version
23+
// Build Number
24+
// Revision
25+
[assembly: AssemblyVersion("1.0.0.0")]
26+
[assembly: AssemblyFileVersion("1.0.0.0")]
27+
28+
// Add some common permissions, these can be removed if not needed
29+
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
30+
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Images, layout descriptions, binary blobs and string dictionaries can be included
2+
in your application as resource files. Various Android APIs are designed to
3+
operate on the resource IDs instead of dealing with images, strings or binary blobs
4+
directly.
5+
6+
For example, a sample Android app that contains a user interface layout (main.xml),
7+
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png)
8+
would keep its resources in the "Resources" directory of the application:
9+
10+
Resources/
11+
drawable-hdpi/
12+
icon.png
13+
14+
drawable-ldpi/
15+
icon.png
16+
17+
drawable-mdpi/
18+
icon.png
19+
20+
layout/
21+
main.xml
22+
23+
values/
24+
strings.xml
25+
26+
In order to get the build system to recognize Android resources, set the build action to
27+
"AndroidResource". The native Android APIs do not operate directly with filenames, but
28+
instead operate on resource IDs. When you compile an Android application that uses resources,
29+
the build system will package the resources for distribution and generate a class called
30+
"Resource" that contains the tokens for each one of the resources included. For example,
31+
for the above Resources layout, this is what the Resource class would expose:
32+
33+
public class Resource {
34+
public class drawable {
35+
public const int icon = 0x123;
36+
}
37+
38+
public class layout {
39+
public const int main = 0x456;
40+
}
41+
42+
public class strings {
43+
public const int first_string = 0xabc;
44+
public const int second_string = 0xbcd;
45+
}
46+
}
47+
48+
You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main
49+
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first
50+
string in the dictionary file values/strings.xml.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
2+
android:viewportWidth="512.034"
3+
android:viewportHeight="512.034"
4+
android:width="512.034dp"
5+
android:height="512.034dp">
6+
<path
7+
android:pathData="M362.684 192.034H149.35c-5.888 0 -10.667 4.779 -10.667 10.667v170.667c0 25.771 18.347 47.296 42.667 52.267v54.4c0 17.643 14.357 32 32 32 17.643 0 32 -14.357 32 -32v-53.333h21.333v53.333c0 17.643 14.357 32 32 32s32 -14.357 32 -32v-54.4c24.32 -4.949 42.667 -26.496 42.667 -52.267V202.701C373.35 196.792 368.572 192.034 362.684 192.034zM311.846 56.845l17.984 -41.963c2.325 -5.419 -0.192 -11.669 -5.611 -13.995 -5.355 -2.347 -11.691 0.171 -13.995 5.611l-17.984 41.984c-11.413 -3.712 -23.573 -5.781 -36.203 -5.781 -12.629 0 -24.789 2.069 -36.203 5.781L201.809 6.498c-2.304 -5.44 -8.64 -7.979 -13.995 -5.611 -5.419 2.325 -7.915 8.597 -5.589 13.995l17.984 41.963c-36.629 19.883 -61.525 58.688 -61.525 103.189 0 5.888 4.779 10.667 10.667 10.667h213.333c5.888 0 10.667 -4.779 10.667 -10.667C373.35 115.533 348.454 76.728 311.846 56.845zM213.35 128.034c-5.888 0 -10.667 -4.779 -10.667 -10.667s4.779 -10.667 10.667 -10.667 10.667 4.779 10.667 10.667S219.238 128.034 213.35 128.034zM298.684 128.034c-5.888 0 -10.667 -4.779 -10.667 -10.667s4.779 -10.667 10.667 -10.667 10.667 4.779 10.667 10.667S304.572 128.034 298.684 128.034zM426.684 192.034c-17.643 0 -32 14.357 -32 32v106.667c0 17.643 14.357 32 32 32 17.643 0 32 -14.357 32 -32V224.034C458.684 206.392 444.327 192.034 426.684 192.034zM85.35 192.034c-17.643 0 -32 14.357 -32 32v106.667c0 17.643 14.357 32 32 32 17.643 0 32 -14.357 32 -32V224.034C117.35 206.392 102.993 192.034 85.35 192.034z"
8+
android:fillColor="#000000" />
9+
</vector>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
2+
android:viewportWidth="512"
3+
android:viewportHeight="512"
4+
android:width="512dp"
5+
android:height="512dp">
6+
<path
7+
android:pathData="M185.255 512c-76.201 -0.439 -139.233 -155.991 -139.233 -235.21 0 -129.404 97.075 -157.734 134.487 -157.734 16.86 0 34.863 6.621 50.742 12.48 11.104 4.087 22.588 8.306 28.975 8.306 3.823 0 12.832 -3.589 20.786 -6.738 16.963 -6.753 38.071 -15.146 62.651 -15.146 0.044 0 0.103 0 0.146 0 18.354 0 74.004 4.028 107.461 54.272l7.837 11.777 -11.279 8.511c-16.113 12.158 -45.513 34.336 -45.513 78.267 0 52.031 33.296 72.041 49.292 81.665 7.061 4.248 14.37 8.628 14.37 18.208 0 6.255 -49.922 140.566 -122.417 140.566 -17.739 0 -30.278 -5.332 -41.338 -10.034 -11.191 -4.761 -20.845 -8.862 -36.797 -8.862 -8.086 0 -18.311 3.823 -29.136 7.881C221.496 505.73 204.752 512 185.753 512H185.255zM351.343 0c1.888 68.076 -46.797 115.304 -95.425 112.342C247.905 58.015 304.54 0 351.343 0z"
8+
android:fillColor="#000000" />
9+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="512dp"
3+
android:height="512dp"
4+
android:viewportWidth="512"
5+
android:viewportHeight="512">
6+
7+
<path
8+
android:fillColor="#000000"
9+
android:pathData="M0 80L0 240 224 240 224 52zM256 48L256 240 512 240 512 16zM256 272L256 464 512 496 512 272zM0 272L0 432 224 460 224 272z" />
10+
</vector>

0 commit comments

Comments
 (0)