使用Visual Studio 2015开发Android 程序

简介: 原文:使用Visual Studio 2015开发Android 程序 环境配置: 操作系统:win 7 64位 IDE:Visual Studio 2015 SDK:installer_r24.3.3-windows 安装前提: 编辑hosts文件(在附件可下载)因为安装过程中要联网更新和注册 安装完成VS之后直接新建android程序会提示: --------------------------- Microsoft Visual Studio --------------------------- 值不能为 null。

原文:使用Visual Studio 2015开发Android 程序

环境配置:

操作系统:win 7 64位

IDE:Visual Studio 2015

SDK:installer_r24.3.3-windows

安装前提:

编辑hosts文件(在附件可下载)因为安装过程中要联网更新和注册

安装完成VS之后直接新建android程序会提示:

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

Microsoft Visual Studio

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

值不能为 null。参数名: path1

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

确定   

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

那是因为VS没有配置android的SDK,接下来我们就设置。

第一步:更新android SDK

自行百度并安装installer_r24.3.3-windows.exe,然后打开安装路径下的SDK Manager选择一个安卓版本更新,比如4.1.2,可以根据需要将其他版本对勾去掉。

然后等待更新完毕:

wps52D1.tmp

然后打开AVD Manager创建一个虚拟机:

wps52E2.tmp

点击右边的Start启动看看能不能起起来。

第二步:新建android项目:

wps52F2.tmp

然后会要求你登陆:

wps5303.tmp

需要先注册,然后登陆。

然后依次点开资源管理器,找到布局文件:

wps5304.tmp

双击打开设计界面:

工具箱上面已经内置了很多控件:

wps5314.tmp

这里无所谓了,喜欢拖就拖,不喜欢就自己写布局代码,咱们完成一个登陆界面:

wps5325.tmp

完整代码如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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">
    <TextView
        android:id="@+id/form_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="初始用户名和密码都是123" />
    <LinearLayout
        android: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">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登录名:" />
        <EditText
            android:id="@+id/txt_login_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="15.0sp" />
    </LinearLayout>
    <LinearLayout
        android: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">
        <TextView
            android:id="@+id/login_pass_edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="密  码:"
            android:textSize="15.0sp" />
        <EditText
            android:id="@+id/txt_login_pwd"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:password="true"
            android:textSize="15.0sp" />
    </LinearLayout>
    <Button
        android: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="登陆" />
</LinearLayout>

这些代码稍微一用力就能看明白。

打开MainActivity 编辑代码如下:

protected override void OnCreate(Bundle bundle)
  {
     base.OnCreate(bundle);
    // Set our view from the "main" layout resource
    SetContentView(Resource.Layout.Main);
    // Get our button from the layout resource,  form_title
    // and attach an event to it
            Button 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 {
                                        string loginName = txtLoginName.Text;
                                        string loginPwd = txtLoginPwd.Text;
                                        if (loginName == loginPwd&& loginName == "123")
                                           {
                                              txtMsg.Text = "登陆成功!";
                                           }
                                    };
  }

含义很简单,就是找到控件,取值,赋值,控件的ID在布局中定义@+id/后面的就是。

智能提示不灵光,暂时忍忍吧。

然后启动,按F5,如果想查看详细信息或者运行中异常,请依次打开logcat:

wps5326.tmp

将输出控制台拉大:

wps5337.tmp

以后在运行中如果奔溃,可以在这里找到详细信息。

在虚拟机中进入控制面板:

wps5347.tmp

启动它,输入信息:

wps5348.tmp

点击登录:

wps5359.tmp

第三步:部署app

经过第二步大家可以在debug目录下找到apk安装文件:

wps5369.tmp

然后一激动就复制到手机中,结果发现根本用不了。

原因是VS中开发的apk需要发布才能安装使用,发布按钮就在

wps536A.tmp

目前是灰的,需要将调试模式改为release才可用:

wps537B.tmp

然后会出现发布向导:

wps537C.tmp

这里您请随意!

wps538D.tmp

然后继续:

wps539D.tmp

记住上面的路径,一会就在这里找安装用APK文件。

然后等黑屏闪2下,就出现了这个期待的文件:

wps53AE.tmp

复制到手机中,安装后,开始得瑟吧!

wps53BE.tmp

host下载

源码下载

目录
相关文章
|
5天前
|
存储 安全 Android开发
安卓应用开发:构建一个高效的用户登录系统
【5月更文挑战第3天】在移动应用开发中,用户登录系统的设计与实现是至关重要的一环。对于安卓平台而言,一个高效、安全且用户体验友好的登录系统能够显著提升应用的用户留存率和市场竞争力。本文将探讨在安卓平台上实现用户登录系统的最佳实践,包括对最新身份验证技术的应用、安全性考量以及性能优化策略。
|
7天前
|
前端开发 Android开发 iOS开发
【Flutter前端技术开发专栏】Flutter在Android与iOS上的性能对比
【4月更文挑战第30天】Flutter 框架实现跨平台移动应用,通过一致的 UI 渲染(Skia 引擎)、热重载功能和响应式框架提高开发效率和用户体验。然而,Android 和 iOS 的系统差异、渲染机制及编译过程影响性能。性能对比显示,iOS 可能因硬件优化提供更流畅体验,而 Android 更具灵活性和广泛硬件支持。开发者可采用代码、资源优化和特定平台优化策略,利用性能分析工具提升应用性能。
【Flutter前端技术开发专栏】Flutter在Android与iOS上的性能对比
|
19小时前
|
Android开发 Kotlin
Kotlin开发Android之基础问题记录
Kotlin开发Android之基础问题记录
6 1
|
20小时前
|
Android开发
Android Studio或IDEA 升级后 不提示错误问题
Android Studio或IDEA 升级后 不提示错误问题
9 1
|
1天前
|
Android开发
Android 盒子开发过程中遇到的问题及解决方法
Android 盒子开发过程中遇到的问题及解决方法
7 2
|
2天前
|
机器学习/深度学习 算法 Android开发
安卓应用开发:打造高效通知管理系统
【5月更文挑战第6天】 在现代移动应用的海洋中,用户经常面临信息过载的挑战。一个精心设计的通知管理系统对于提升用户体验至关重要。本文将探讨在安卓平台上如何实现一个高效的通知管理系统,包括最佳实践、系统架构设计以及性能优化技巧。通过分析安卓通知渠道和优先级设置,我们的目标是帮助开发者构建出既能吸引用户注意,又不会引发干扰的智能通知系统。
14 2
|
2天前
|
安全 Linux Android开发
FFmpeg开发笔记(十六)Linux交叉编译Android的OpenSSL库
该文介绍了如何在Linux服务器上交叉编译Android的FFmpeg库以支持HTTPS视频播放。首先,从GitHub下载openssl源码,解压后通过编译脚本`build_openssl.sh`生成64位静态库。接着,更新环境变量加载openssl,并编辑FFmpeg配置脚本`config_ffmpeg_openssl.sh`启用openssl支持。然后,编译安装FFmpeg。最后,将编译好的库文件导入App工程的相应目录,修改视频链接为HTTPS,App即可播放HTTPS在线视频。
FFmpeg开发笔记(十六)Linux交叉编译Android的OpenSSL库
|
7天前
|
存储 Java Android开发
安卓应用开发中的内存优化策略
【4月更文挑战第30天】在移动开发领域,尤其是安卓平台上,内存管理是影响应用性能和用户体验的关键因素。由于安卓设备的硬件资源有限,不合理的内存使用会导致应用响应缓慢、消耗过多电量甚至崩溃。本文将探讨针对安卓平台的内存优化技巧,旨在帮助开发者提高应用的性能和稳定性,从而提升用户满意度。我们将详细讨论内存泄漏的预防、合理的内存分配策略以及高效的内存回收方法。
|
存储 SQL 关系型数据库
Android数据库开发基础入门【附完整案例】
Android数据库开发基础入门【附完整案例】
411 0
Android数据库开发基础入门【附完整案例】
|
XML 前端开发 程序员
【Android开发】小白入门必看的”四框“使用教程,你学废了嘛?
【Android开发】小白入门必看的”四框“使用教程,你学废了嘛?
162 0
【Android开发】小白入门必看的”四框“使用教程,你学废了嘛?