Configuring the Android Emulator
This is the first leak, configure the parameters of the VS, after the new Android project, you will find that the toolbar under the menu will be more than the Android-related toolbar, the red circle is the AVD.
After you open the AVD, you can select a device from the template and then adjust the detail parameters yourself.
Then choose the version to simulate, because the app has Bluetooth ble support needs, so choose at least API Level18, note If the Haxm,cpu/abi item installed must choose "Intel Atom (x86)", if not, the description component is not installed, hurry to download and then come Another point of attention is that memory is at least 3g, or run up to a dog, don't ask me how I know ...
Run effect
Build an Android APP
Create a new empty Android project from the New Project dialog box
The new project base directory is as follows (Layout1.axml and Activity1.cs are added later)
Androidmanifest.xml
The first thing to say is Androidmanifest.xml, which is a very important part of the app, but in VS you don't have to write the configuration in the same way as in the Java Development environment, open to see only the basic parts, and the rest of VS will be complete at compile time. Content in Androidmanifest.xml can be configured to complete in the project properties
(Configuration of namespace, API level, etc.)
(app version, name, permissions, etc.)
(There is no practical experience here, keep the default, and so on to figure out again)
Assets and Resource Resources directory
Assets is a binary resource file, such as fonts, sounds, access as follows (refer to the AboutAssets.txt file in the Assets directory with sample code):
//Any raw assets-want to be deployed with your application can is placed in//This directory (and child directories) and given a Build Action of "Androidasset".////These files would be deployed with the you package and would be accessible using Android ' s//Assetmanager, like this: Public classreadasset:activity{protected Override voidOnCreate (Bundle bundle) {Base. OnCreate (bundle); InputStream input= Assets.open ("My_asset.txt"); }}//Additionally, some Android functions would automatically load asset files:Typeface TF= Typeface.createfromasset (Context.assets,"Fonts/samplefont.ttf");
The resource directory contains resource files such as layouts, pictures, string dictionaries, and also a description of the invocation of the resource (AboutResources.txt in the directory):
/*Images, layout descriptions, binary blobs and string dictionaries can be included in your application as resource files. Various Android APIs is designed to operate on the resource IDs instead of dealing with images, strings or binary blobs Directly. For example, a sample Android app, this contains a user interface layout (main.axml), an internationalization string table ( Strings.xml) and some icons (drawable-xxx/icon.png) would keep its resources in the "Resources" directory of the Applicati On:resources/drawable/icon.png layout/main.axml Values/strings.xmlin order to get the BU ILD system to recognize Android resources, set the build action to "Androidresource". The native Android APIs does not operate directly with filenames, but instead operate on resource IDs. When you compile a Android application that uses resources, the build system would package the resources for distribution and generate a class called "R" (this was an Android convention) that conTains the tokens for each one of the resources included. For example, for the above Resources layout, this is what the R class would expose:*/ Public classR { Public classdrawable { Public Const inticon =0x123; } Public classLayout { Public Const intMain =0x456; } Public classStrings { Public Const intFirst_string =0XABC; Public Const intSecond_string =0XBCD; }}/*You would then use R.drawable.icon to reference the Drawable/icon.png file, or R.layout.main to reference the layout/m Ain.axml file, or r.strings.first_string to reference the first string in the dictionary file values/strings.xml.*/
Activity Code
In addition to these directories, the other is the activity of the code and its own class code, the app's default startup activity as long as the device class related properties are OK, do not need a specific name, the key note: "Mainlauncher = true, Icon =" @ Drawable/icon "". As for the other code is not the same as the basic Java?
[Activity (Label ="Demo app_01", Mainlauncher =true, Icon ="@drawable/icon")] Public classmainactivity:activity {protected Override voidOnCreate (Bundle bundle) {Base. OnCreate (bundle); //Set Our view from the "main" layout resourceSetcontentview (Resource.Layout.Main); //Get Our buttons from the layout resource,//And attach an event to it } }
If you click the button to launch another activity code, is there a familiar feeling?
Button btnopenactivity = findviewbyid<button>+ = (sender, e) + = {new Intent (thistypeof(Activity1)); StartActivity (intent); };
Add two buttons and some simple code to the activity after debugging run:
VS2015 Android Development Series 02--with VS to develop the first Android APP