Android (Xamarin) Tour (i)

Source: Internet
Author: User

Original: Android (Xamarin) Tour (i)

I won't say a word about Xamarin.

is an IDE that writes Android and iOS apps, and there's a plugin that starts with visual Studio2010. As long as the development of what, I think here is not as good as their own to Baidu.

In the following:

I. Installation and configuration (for example, Visual Studio Pro 2015)

  Visual Studio2015 directly provides this plug-in selection, a little hint, if you want to install, it is best to prepare 10 hours of the plan , and the speed is good, because to download the Android API and Java SDK and other related components, is very time-consuming, of course, can be installed in steps, for example, first install the default configuration, only install the default C # configuration items, and then repair the time, click Install, then choose Xamarin, in fact, this purpose is only to let the visual error, if the speed is not enough, or very slow very slow.

, in this case

    

Is originally installed in the case of C # default configuration, run the installation package again, there will be three buttons ' modify ', ' repair ', ' uninstall ', at this time we choose to modify, and then cross-platform mobile development of Xamarin front tick is OK, as for the Android SDK and Java SDK, Manual download is highly recommended.

For convenience, go directly to http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html to download the Java SDK , go to Baidu search for Android Studio, you can download the Android SDK and so on related things. The SDK Manage, AVD Manager will appear after the installation is complete, which is enough for us.

Android Studio specific installation:http://www.cnblogs.com/mfryf/archive/2013/05/20/3089143.html

After the installation is complete, download the SDK and Android virtual machine check. After completion, you can configure, if the direct one-time installation, is not required to configure, if it is separate, you can open the visual studio2015 "Tools" → "options" find Xamarin, and then configure it separately.

    

    

These include Android downloads, SDK updates, and virtual machine management, among others. There are many ways to do it online. I am here to provide you with the host mode of API 23, found on the internet is generally API19 before, I also looked for a long time to find the API 23 proxy way.

Path: C:\Windows\System32\Drivers\etc in this folder under the Hosts file, right-click, Notepad or other text editor open, add at the end

  74.125.20.31 dl-ssl.google.com
74.125.136.138 developer.android.com
203.208.41.128 dl.google.com

  These three addresses can be, please note that the three address added to the Hosts file after you can

Second, the important moment has come, we also fly a bit of code

  A simple example, please refer to:http://www.cnblogs.com/madyina/p/4671708.html Actually, the eldest brother, has already made one, but before I went wrong is the previous I mentioned, API update and SDK Manager here, the other can be referred to the elder brother. Here, I will use the control and some of the wording, and share with you.

Before loading, I'll tidy up the entire Android file directory.

    

Directory structure

1, the properties of this refers to the attributes of the project, where androidmanifest.xml in Java is a very important registration file, but here specifically how to use, please forgive me, I have not figured out. As for AssemblyInfo.cs This document I will not say.

2, assets This folder, currently I do not understand, but I feel he is an explanatory folder, can ignore, including the documents inside.

3, resources This folder is quite important ah, basically the program inside all the things are out from here.

(1) drawable Resources folder, I believe you see the suffix name, similar resource files can be placed here.

(2) Layout view folder, we can see, can give us visual effects, are placed here.

This is main.xml.

(3) The folder of the values custom XML file, which is stored in some common XML information.

4, Resource.Designer.cs This file is all the resources files in this file to generate a unique correspondence .

  

This is the Drawable folder we just saw, and each of the images here generates a unique corresponding constant.

5, Gettingstarted.xamarin This, do not know how to explain, look at the picture, a moment to understand

  

6, Mainactivity This is also the most important one CS file, because our backstage code basically all goes out from here.

  Tips : When adding a resource file, please note the XML file, followed by "s" although I do not know why this thing this piece of crap, but, do not add "s" My resource file ID inside not found, that is not used.

Let's start with the use of some components directly

  First, TextView

<textview        android:text= "@string/tv_phone"        android:layout_width= "match_parent"        android:layout_ height= "Wrap_content"        android:textcolor= "@color/yellow"        android:autolink= "Phone"        android:textsize= "48px"        android:id= "@+id/tv_color"        android:gravity= "center"/>

This is the interface code, I think this is not necessary to explain, I will say the textcolor and text of the two, first of all, we will see here is a @, "@" in Android, refers to the meaning of resources. @string, reference string. @string/tv_phone here means referencing strings.xml name= "Tv_phone" resources below. As mentioned earlier, the Strings.xml file is defined under the Resources folder. Here is a use of resource files.

This is my strings.xml file, I believe you have seen what.

Here, I suggest that everyone is autolink this attribute, this property is the phone number can be dialed directly meaning.

 Second, ImageView

<imageview        android:src= "@drawable/administrator"        android:layout_width= "Match_parent"        android: layout_height= "Wrap_content"        android:id= "@+id/iv_change_url"/>

This is the case, it is worth noting that if you are directly dragged from the toolbar ImageView, then please pay attention to his wording android:src= "@android:d rawable/ic_menu_gallery" This thing in front of @android really is a 喳喳, because of this problem, I made a small half an hour to find the problem, directly with @drawable on it, but because an android did not delete, the various generation is unsuccessful.

  Third, EditText

<edittext        android:id= "@+id/et_txt"        android:layout_width= "fill_parent"        android:layout_height= " Wrap_content "        android:inputtype=" phone "        android:hint=" @string/et_txt "/>

For this component, explain the inputtype= "phone" here means that when we start to enter the default is to open the Dial keyboard, because the phone is a number, meaning is to open the digital keyboard, there is hint, can be called the message, is the placeholder attribute inside the HTML5.

  Iv. Button

<button        android:id= "@+id/btn_call"        android:layout_width= "fill_parent"        android:layout_height= " Wrap_content "        android:text=" @string/btn_changcolor "/>

For button, the interface is really like this, but the main thing is our backstage code OH.

Five, backstage code

  As already mentioned, backstage code is written under Mainactivity.

And looking at this thing like a filter

  

The label is the name of the header of your apk, icon is the corresponding icons, the next look at the comments can be

  

1, take the front btn_changcolor as an example, his click event should be written like this

Write the corresponding event

  

2, because the implementation of View.ionclicklistener this interface, the interface is so implemented

  

At this point we can also use the Setonclicklistener method, then, because the implementation of the interface, just do it, OK.

   Button Btn_change = findviewbyid<button> (Resource.Id.btn_Chang);   Btn_change. Setonclicklistener (this);

  

3, can also be traditional wording

  

The corresponding event

  

4, on the basis of traditional writing, the previous version I have not tried, but Visual Studio 2015 can do so

  

OK, right here, forgive me for being a novice. Interested people can study together.

Android (Xamarin) Tour (i)

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.