在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
我有罪啊,我用了一下午时间,终于无师自学,用C#开发了俺的第一个Android 浏览器APP,我对不起java 社区啊(附开发过程讲解)
开发流程: 安装 VS2010、安装 Android SDK、配置 AVD(android) 模拟器
调试的时候打开 ADV(android 模拟器) 在里面你自己添加一个机器的型号,设置好分辨率,内存大小,SD卡,启动之后,就可以调试了! 开始开发:新建 android application 产生代码如下:Activity1.cs 代码如下: using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; using Android.Webkit; namespace hz.android.test { [Activity (Label = "hz.android.test", MainLauncher = true)] public class Activity1 : Activity { int count = 1; protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); Button button = FindViewById<Button> (Resource.Id.myButton); WebView webView = FindViewById<WebView> (Resource.Id.webView1); button.Click += delegate { button.Text = string.Format ("{0} clicks!", count++); webView.LoadUrl("http://blog.csdn.net/tengyunjiawu_com/article/details/8565766"); }; } } }
界面设计是可视化的,所见即所得的,比 netneans 和 eclipse 强多了,还有很多各种各样的控件! netneans 和 eclipse 界面都要自己写 axml文件,这个能拖拉好之后自动生成: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:andro android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android: android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <WebView android:layout_width="fill_parent" android:layout_height="220.7dp" android: android:layout_marginBottom="50.0dp" /> <EditText android:inputType="textEmailAddress" android:layout_width="fill_parent" android:layout_height="wrap_content" android: android:text="[email protected] QQ:99923309" android:linksClickable="true" /> <DatePicker android:layout_width="fill_parent" android:layout_height="wrap_content" android: /> <CheckedTextView android:layout_width="fill_parent" android:layout_height="wrap_content" android: /> </LinearLayout>
Resource.designer.cs 这个相当于 netbeans 或 java 开发 Android时自动生成的R.java 类代码: //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.239 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace hz.android.test { public partial class Resource { public partial class Attribute { private Attribute() { } } public partial class Drawable { // aapt resource value: 0x7f020000 public const int Icon = 2130837504; // aapt resource value: 0x7f020001 public const int lbs = 2130837505; private Drawable() { } } public partial class Id { // aapt resource value: 0x7f050004 public const int checkedTextView1 = 2131034116; // aapt resource value: 0x7f050003 public const int datePicker1 = 2131034115; // aapt resource value: 0x7f050002 public const int editText1 = 2131034114; // aapt resource value: 0x7f050000 public const int myButton = 2131034112; // aapt resource value: 0x7f050001 public const int webView1 = 2131034113; private Id() { } } public partial class Layout { // aapt resource value: 0x7f030000 public const int Main = 2130903040; private Layout() { } } public partial class String { // aapt resource value: 0x7f040001 public const int app_name = 2130968577; // aapt resource value: 0x7f040000 public const int hello = 2130968576; private String() { } } } }
调试的时候打开 ADV(android 模拟器) 在里面你自己添加一个机器的型号,设置好分辨率,内存大小,SD卡,启动之后,就可以调试了! 真机(在三星、摩托罗拉、HTC 上均测试通过)效果如下: 上面按钮点击后效果:
下载地址:http://pan.baidu.com/share/link?shareid=383627&uk=201606611 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论