添加xamarinFormApp例子,安卓,iOS,WPF
@@ -0,0 +1,19 @@
 | 
			
		||||
Any raw assets you want to be deployed with your application can be placed in
 | 
			
		||||
this directory (and child directories) and given a Build Action of "AndroidAsset".
 | 
			
		||||
 | 
			
		||||
These files will be deployed with your package and will be accessible using Android's
 | 
			
		||||
AssetManager, like this:
 | 
			
		||||
 | 
			
		||||
public class ReadAsset : Activity
 | 
			
		||||
{
 | 
			
		||||
    protected override void OnCreate (Bundle bundle)
 | 
			
		||||
    {
 | 
			
		||||
        base.OnCreate (bundle);
 | 
			
		||||
 | 
			
		||||
        InputStream input = Assets.Open ("my_asset.txt");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Additionally, some Android functions will automatically load asset files:
 | 
			
		||||
 | 
			
		||||
Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf");
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
using Android.App;
 | 
			
		||||
using Android.Content.PM;
 | 
			
		||||
using Android.Runtime;
 | 
			
		||||
using Android.Views;
 | 
			
		||||
using Android.Widget;
 | 
			
		||||
using Android.OS;
 | 
			
		||||
 | 
			
		||||
namespace xamarinFormApp.Droid
 | 
			
		||||
{
 | 
			
		||||
    [Activity(Label = "xamarinFormApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
 | 
			
		||||
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
 | 
			
		||||
    {
 | 
			
		||||
        protected override void OnCreate(Bundle savedInstanceState)
 | 
			
		||||
        {
 | 
			
		||||
            TabLayoutResource = Resource.Layout.Tabbar;
 | 
			
		||||
            ToolbarResource = Resource.Layout.Toolbar;
 | 
			
		||||
 | 
			
		||||
            base.OnCreate(savedInstanceState);
 | 
			
		||||
 | 
			
		||||
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
 | 
			
		||||
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
 | 
			
		||||
            LoadApplication(new App());
 | 
			
		||||
        }
 | 
			
		||||
        public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
 | 
			
		||||
        {
 | 
			
		||||
            Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
 | 
			
		||||
 | 
			
		||||
            base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,6 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.xamarinformapp" android:installLocation="auto">
 | 
			
		||||
	<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
 | 
			
		||||
	<application android:label="xamarinFormApp.Android" android:theme="@style/MainTheme"></application>
 | 
			
		||||
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 | 
			
		||||
</manifest>
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
using System.Reflection;
 | 
			
		||||
using System.Runtime.CompilerServices;
 | 
			
		||||
using System.Runtime.InteropServices;
 | 
			
		||||
using Android.App;
 | 
			
		||||
 | 
			
		||||
// General Information about an assembly is controlled through the following 
 | 
			
		||||
// set of attributes. Change these attribute values to modify the information
 | 
			
		||||
// associated with an assembly.
 | 
			
		||||
[assembly: AssemblyTitle("xamarinFormApp.Android")]
 | 
			
		||||
[assembly: AssemblyDescription("")]
 | 
			
		||||
[assembly: AssemblyConfiguration("")]
 | 
			
		||||
[assembly: AssemblyCompany("")]
 | 
			
		||||
[assembly: AssemblyProduct("xamarinFormApp.Android")]
 | 
			
		||||
[assembly: AssemblyCopyright("Copyright ©  2014")]
 | 
			
		||||
[assembly: AssemblyTrademark("")]
 | 
			
		||||
[assembly: AssemblyCulture("")]
 | 
			
		||||
[assembly: ComVisible(false)]
 | 
			
		||||
 | 
			
		||||
// Version information for an assembly consists of the following four values:
 | 
			
		||||
//
 | 
			
		||||
//      Major Version
 | 
			
		||||
//      Minor Version 
 | 
			
		||||
//      Build Number
 | 
			
		||||
//      Revision
 | 
			
		||||
[assembly: AssemblyVersion("1.0.0.0")]
 | 
			
		||||
[assembly: AssemblyFileVersion("1.0.0.0")]
 | 
			
		||||
 | 
			
		||||
// Add some common permissions, these can be removed if not needed
 | 
			
		||||
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
 | 
			
		||||
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
Images, layout descriptions, binary blobs and string dictionaries can be included 
 | 
			
		||||
in your application as resource files.  Various Android APIs are designed to 
 | 
			
		||||
operate on the resource IDs instead of dealing with images, strings or binary blobs 
 | 
			
		||||
directly.
 | 
			
		||||
 | 
			
		||||
For example, a sample Android app that contains a user interface layout (main.xml),
 | 
			
		||||
an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 
 | 
			
		||||
would keep its resources in the "Resources" directory of the application:
 | 
			
		||||
 | 
			
		||||
Resources/
 | 
			
		||||
    drawable-hdpi/
 | 
			
		||||
        icon.png
 | 
			
		||||
 | 
			
		||||
    drawable-ldpi/
 | 
			
		||||
        icon.png
 | 
			
		||||
 | 
			
		||||
    drawable-mdpi/
 | 
			
		||||
        icon.png
 | 
			
		||||
 | 
			
		||||
    layout/
 | 
			
		||||
        main.xml
 | 
			
		||||
 | 
			
		||||
    values/
 | 
			
		||||
        strings.xml
 | 
			
		||||
 | 
			
		||||
In order to get the build system to recognize Android resources, set the build action to
 | 
			
		||||
"AndroidResource".  The native Android APIs do not operate directly with filenames, but 
 | 
			
		||||
instead operate on resource IDs.  When you compile an Android application that uses resources, 
 | 
			
		||||
the build system will package the resources for distribution and generate a class called
 | 
			
		||||
"Resource" that contains the tokens for each one of the resources included. For example, 
 | 
			
		||||
for the above Resources layout, this is what the Resource class would expose:
 | 
			
		||||
 | 
			
		||||
public class Resource {
 | 
			
		||||
    public class drawable {
 | 
			
		||||
        public const int icon = 0x123;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class layout {
 | 
			
		||||
        public const int main = 0x456;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public class strings {
 | 
			
		||||
        public const int first_string = 0xabc;
 | 
			
		||||
        public const int second_string = 0xbcd;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
You would then use R.drawable.icon to reference the drawable/icon.png file, or Resource.layout.main 
 | 
			
		||||
to reference the layout/main.xml file, or Resource.strings.first_string to reference the first 
 | 
			
		||||
string in the dictionary file values/strings.xml.
 | 
			
		||||
							
								
								
									
										14056
									
								
								Examples/xamarinFormApp/xamarinFormApp.Android/Resources/Resource.designer.cs
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						| 
		 After Width: | Height: | Size: 518 B  | 
| 
		 After Width: | Height: | Size: 415 B  | 
| 
		 After Width: | Height: | Size: 21 KiB  | 
@@ -0,0 +1,11 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    xmlns:app="http://schemas.android.com/apk/res-auto"
 | 
			
		||||
    android:id="@+id/sliding_tabs"
 | 
			
		||||
    android:layout_width="match_parent"
 | 
			
		||||
    android:layout_height="wrap_content"
 | 
			
		||||
    android:background="?attr/colorPrimary"
 | 
			
		||||
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
 | 
			
		||||
    app:tabIndicatorColor="@android:color/white"
 | 
			
		||||
    app:tabGravity="fill"
 | 
			
		||||
    app:tabMode="fixed" />
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
<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" />
 | 
			
		||||
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
 | 
			
		||||
    <background android:drawable="@color/launcher_background" />
 | 
			
		||||
    <foreground android:drawable="@mipmap/launcher_foreground" />
 | 
			
		||||
</adaptive-icon>
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
 | 
			
		||||
    <background android:drawable="@color/launcher_background" />
 | 
			
		||||
    <foreground android:drawable="@mipmap/launcher_foreground" />
 | 
			
		||||
</adaptive-icon>
 | 
			
		||||
| 
		 After Width: | Height: | Size: 4.6 KiB  | 
| 
		 After Width: | Height: | Size: 11 KiB  | 
| 
		 After Width: | Height: | Size: 2.7 KiB  | 
| 
		 After Width: | Height: | Size: 6.3 KiB  | 
| 
		 After Width: | Height: | Size: 6.9 KiB  | 
| 
		 After Width: | Height: | Size: 18 KiB  | 
| 
		 After Width: | Height: | Size: 12 KiB  | 
| 
		 After Width: | Height: | Size: 33 KiB  | 
| 
		 After Width: | Height: | Size: 19 KiB  | 
| 
		 After Width: | Height: | Size: 51 KiB  | 
@@ -0,0 +1,7 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<resources>
 | 
			
		||||
    <color name="launcher_background">#FFFFFF</color>
 | 
			
		||||
    <color name="colorPrimary">#3F51B5</color>
 | 
			
		||||
    <color name="colorPrimaryDark">#303F9F</color>
 | 
			
		||||
    <color name="colorAccent">#FF4081</color>
 | 
			
		||||
</resources>
 | 
			
		||||
@@ -0,0 +1,18 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8" ?>
 | 
			
		||||
<resources>
 | 
			
		||||
 | 
			
		||||
  <style name="MainTheme" parent="MainTheme.Base">
 | 
			
		||||
    <!-- As of Xamarin.Forms 4.6 the theme has moved into the Forms binary -->
 | 
			
		||||
    <!-- If you want to override anything you can do that here. -->
 | 
			
		||||
    <!-- Underneath are a couple of entries to get you started. -->
 | 
			
		||||
 | 
			
		||||
    <!-- Set theme colors from https://aka.ms/material-colors -->
 | 
			
		||||
    <!-- colorPrimary is used for the default action bar background -->
 | 
			
		||||
    <!--<item name="colorPrimary">#2196F3</item>-->
 | 
			
		||||
    <!-- colorPrimaryDark is used for the status bar -->
 | 
			
		||||
    <!--<item name="colorPrimaryDark">#1976D2</item>-->
 | 
			
		||||
    <!-- colorAccent is used as the default value for colorControlActivated
 | 
			
		||||
         which is used to tint widgets -->
 | 
			
		||||
    <!--<item name="colorAccent">#FF4081</item>-->
 | 
			
		||||
  </style>
 | 
			
		||||
</resources>
 | 
			
		||||
@@ -0,0 +1,115 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
 | 
			
		||||
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
 | 
			
		||||
    <ProjectGuid>{0BFC3652-7CD1-49E4-BA9A-70E5EC818FCE}</ProjectGuid>
 | 
			
		||||
    <ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
 | 
			
		||||
    <TemplateGuid>{6968b3a4-1835-46a3-ac5c-1ae33b475983}</TemplateGuid>
 | 
			
		||||
    <OutputType>Library</OutputType>
 | 
			
		||||
    <RootNamespace>xamarinFormApp.Droid</RootNamespace>
 | 
			
		||||
    <AssemblyName>xamarinFormApp.Android</AssemblyName>
 | 
			
		||||
    <Deterministic>True</Deterministic>
 | 
			
		||||
    <AndroidApplication>True</AndroidApplication>
 | 
			
		||||
    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
 | 
			
		||||
    <AndroidResgenClass>Resource</AndroidResgenClass>
 | 
			
		||||
    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
 | 
			
		||||
    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
 | 
			
		||||
    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
 | 
			
		||||
    <AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
 | 
			
		||||
    <TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
 | 
			
		||||
    <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
 | 
			
		||||
    <AndroidUseAapt2>true</AndroidUseAapt2>
 | 
			
		||||
    <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
 | 
			
		||||
    <NuGetPackageImportStamp>
 | 
			
		||||
    </NuGetPackageImportStamp>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <DebugType>portable</DebugType>
 | 
			
		||||
    <Optimize>false</Optimize>
 | 
			
		||||
    <OutputPath>bin\Debug</OutputPath>
 | 
			
		||||
    <DefineConstants>DEBUG;</DefineConstants>
 | 
			
		||||
    <ErrorReport>prompt</ErrorReport>
 | 
			
		||||
    <WarningLevel>4</WarningLevel>
 | 
			
		||||
    <AndroidLinkMode>None</AndroidLinkMode>
 | 
			
		||||
    <AotAssemblies>false</AotAssemblies>
 | 
			
		||||
    <EnableLLVM>false</EnableLLVM>
 | 
			
		||||
    <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
 | 
			
		||||
    <BundleAssemblies>false</BundleAssemblies>
 | 
			
		||||
    <MandroidI18n>CJK;West</MandroidI18n>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
 | 
			
		||||
    <DebugSymbols>true</DebugSymbols>
 | 
			
		||||
    <DebugType>portable</DebugType>
 | 
			
		||||
    <Optimize>true</Optimize>
 | 
			
		||||
    <OutputPath>bin\Release</OutputPath>
 | 
			
		||||
    <ErrorReport>prompt</ErrorReport>
 | 
			
		||||
    <WarningLevel>4</WarningLevel>
 | 
			
		||||
    <AndroidManagedSymbols>true</AndroidManagedSymbols>
 | 
			
		||||
    <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
 | 
			
		||||
    <AotAssemblies>false</AotAssemblies>
 | 
			
		||||
    <EnableLLVM>false</EnableLLVM>
 | 
			
		||||
    <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
 | 
			
		||||
    <BundleAssemblies>false</BundleAssemblies>
 | 
			
		||||
    <MandroidI18n>CJK;West</MandroidI18n>
 | 
			
		||||
    <AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
 | 
			
		||||
    <AndroidLinkMode>None</AndroidLinkMode>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Reference Include="Mono.Android" />
 | 
			
		||||
    <Reference Include="System" />
 | 
			
		||||
    <Reference Include="System.Core" />
 | 
			
		||||
    <Reference Include="System.Numerics" />
 | 
			
		||||
    <Reference Include="System.Numerics.Vectors" />
 | 
			
		||||
    <Reference Include="System.Xml.Linq" />
 | 
			
		||||
    <Reference Include="System.Xml" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="Xamarin.Forms" Version="4.8.0.1687" />
 | 
			
		||||
    <PackageReference Include="Xamarin.Essentials" Version="1.5.3.2" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <Compile Include="MainActivity.cs" />
 | 
			
		||||
    <Compile Include="Resources\Resource.designer.cs" />
 | 
			
		||||
    <Compile Include="Properties\AssemblyInfo.cs" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <None Include="Resources\AboutResources.txt" />
 | 
			
		||||
    <None Include="Assets\AboutAssets.txt" />
 | 
			
		||||
    <None Include="Properties\AndroidManifest.xml" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <AndroidResource Include="Resources\layout\Tabbar.xml" />
 | 
			
		||||
    <AndroidResource Include="Resources\layout\Toolbar.xml" />
 | 
			
		||||
    <AndroidResource Include="Resources\values\styles.xml" />
 | 
			
		||||
    <AndroidResource Include="Resources\values\colors.xml" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-hdpi\icon.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\drawable\xamarin_logo.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\drawable\icon_about.png" />
 | 
			
		||||
    <AndroidResource Include="Resources\drawable\icon_feed.png" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <ProjectReference Include="..\xamarinFormApp\xamarinFormApp.csproj">
 | 
			
		||||
      <Project>{19768622-95F4-4D1B-AAF4-090274F22EB5}</Project>
 | 
			
		||||
      <Name>xamarinFormApp</Name>
 | 
			
		||||
    </ProjectReference>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
 | 
			
		||||
  <ProjectExtensions>
 | 
			
		||||
    <VisualStudio>
 | 
			
		||||
      <UserProperties TriggeredFromHotReload="False" />
 | 
			
		||||
    </VisualStudio>
 | 
			
		||||
  </ProjectExtensions>
 | 
			
		||||
</Project>
 | 
			
		||||