Developing Android programs with Visual Studio 2015

Source: Internet
Author: User

Environment configuration:

Operating system: Win 7 64-bit

Ide:visual Studio 2015

Sdk:installer_r24.3.3-windows

Installation Prerequisites:

Edit the Hosts file (available for download in the attachment) because networking updates and registrations are needed during installation

The new Android program will prompt you when the installation completes vs:

---------------------------

Microsoft Visual Studio

---------------------------

The value cannot be null. Parameter name: path1

---------------------------

Are you sure

---------------------------

That's because vs doesn't have an Android SDK configured, so we'll set it up.

First step: Update the Android SDK

Self-Baidu and install Installer_r24.3.3-windows.exe, and then open the installation path under the SDK manager to select an Android version of the update, such as 4.1.2, you can remove other versions as needed.

Then wait for the update to complete:

Then open the AVD Manager to create a virtual machine:

Click Start on the right to see if you can get up.

Step Two: Create a new Android project:

You will then be asked to log in:

Need to register first, then login.

Then click Open Explorer to locate the layout file:

Double-click to open the design interface:

There are a number of controls built into the Toolbox:

It doesn't matter, like drag on the drag, do not like to write their own layout code, we completed a landing interface:

Complete code such as:

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"android:orientation= "vertical"Android:layout_margin= "5dip">    <TextViewAndroid:id= "@+id/form_title"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Initial user name and password are 123" />    <LinearLayoutAndroid:id= "@+id/layout_login_name"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_margin= "5.0dip"Android:layout_margintop= "10.0dip"android:orientation= "Horizontal">        <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Login name:" />        <EditTextAndroid:id= "@+id/txt_login_name"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:textsize= "15.0SP" />    </LinearLayout>    <LinearLayoutAndroid:id= "@+id/login_pwd_layout"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:layout_below= "@id/layout_login_name"Android:layout_centerhorizontal= "true"Android:layout_margin= "5.0dip"android:orientation= "Horizontal">        <TextViewAndroid:id= "@+id/login_pass_edit"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Password:"android:textsize= "15.0SP" />        <EditTextAndroid:id= "@+id/txt_login_pwd"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:password= "true"android:textsize= "15.0SP" />    </LinearLayout>    <ButtonAndroid:id= "@+id/btn_login"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"android:layout_gravity= "Center"android:gravity= "Center"Android:onclick= "Btn_click"Android:text= "Login" /></LinearLayout>

The code can be understood a little harder.

Open the Mainactivity edit code as follows:

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, Form_title    //And attach an event to itbutton Button= findviewbyid<button>(Resource.Id.btn_login); EditText Txtloginname= findviewbyid<edittext>(Resource.Id.txt_login_name); EditText txtloginpwd= findviewbyid<edittext>(RESOURCE.ID.TXT_LOGIN_PWD); TextView txtmsg= findviewbyid<textview>(Resource.Id.form_title); button. Click+=Delegate {stringLoginName =Txtloginname.text;stringLoginpwd =Txtloginpwd.text;if(LoginName = = loginpwd&& LoginName = ="123") {Txtmsg.text="Landing Success! ";  }                                    }; }

The meaning is simple, is to find the control, value, assignment, the ID of the control in the layout is defined @+id/after.

Smart Tips not light, temporarily endure it.

Then start, press F5, and if you want to see more information or run an exception, open Logcat in turn:

Pull the output console large:

Later in the run if the crash, you can find detailed information here.

In the virtual machine, go to the Control Panel:

Start it, enter the information:

Click Login:

Step three: Deploy the app

After the second step, you can find the APK installation file in the Debug directory:

Then the excitement is copied to the phone, the results found that there is no use.

The reason is that the apk developed in VS has to be released for installation, and the Publish button is

Currently Gray, the debug mode needs to be changed to release to be available:

Then the Publish Wizard appears:

Please feel free here!

Then continue:

Remember the path above and a few will look for the installation apk file here.

Then wait for the black screen Flash 2, there is the expected file:

Copy to the phone, after installation, start to go!

Host Download

SOURCE download

Developing Android programs with Visual Studio 2015

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.