使用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下载

源码下载

目录
相关文章
|
3天前
|
Linux 编译器 Android开发
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
在Linux环境下,本文指导如何交叉编译x265的so库以适应Android。首先,需安装cmake和下载android-ndk-r21e。接着,下载x265源码,修改crosscompile.cmake的编译器设置。配置x265源码,使用指定的NDK路径,并在配置界面修改相关选项。随后,修改编译规则,编译并安装x265,调整pc描述文件并更新PKG_CONFIG_PATH。最后,修改FFmpeg配置脚本启用x265支持,编译安装FFmpeg,将生成的so文件导入Android工程,调整gradle配置以确保顺利运行。
24 1
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
|
25天前
|
Java Android开发
Android 开发获取通知栏权限时会出现两个应用图标
Android 开发获取通知栏权限时会出现两个应用图标
12 0
|
17天前
|
XML 开发工具 Android开发
构建高效的安卓应用:使用Jetpack Compose优化UI开发
【4月更文挑战第7天】 随着Android开发不断进化,开发者面临着提高应用性能与简化UI构建流程的双重挑战。本文将探讨如何使用Jetpack Compose这一现代UI工具包来优化安卓应用的开发流程,并提升用户界面的流畅性与一致性。通过介绍Jetpack Compose的核心概念、与传统方法的区别以及实际集成步骤,我们旨在提供一种高效且可靠的解决方案,以帮助开发者构建响应迅速且用户体验优良的安卓应用。
|
19天前
|
监控 算法 Android开发
安卓应用开发:打造高效启动流程
【4月更文挑战第5天】 在移动应用的世界中,用户的第一印象至关重要。特别是对于安卓应用而言,启动时间是用户体验的关键指标之一。本文将深入探讨如何优化安卓应用的启动流程,从而减少启动时间,提升用户满意度。我们将从分析应用启动流程的各个阶段入手,提出一系列实用的技术策略,包括代码层面的优化、资源加载的管理以及异步初始化等,帮助开发者构建快速响应的安卓应用。
|
19天前
|
Java Android开发
Android开发之使用OpenGL实现翻书动画
本文讲述了如何使用OpenGL实现更平滑、逼真的电子书翻页动画,以解决传统贝塞尔曲线方法存在的卡顿和阴影问题。作者分享了一个改造后的外国代码示例,提供了从前往后和从后往前的翻页效果动图。文章附带了`GlTurnActivity`的Java代码片段,展示如何加载和显示书籍图片。完整工程代码可在作者的GitHub找到:https://github.com/aqi00/note/tree/master/ExmOpenGL。
21 1
Android开发之使用OpenGL实现翻书动画
|
19天前
|
Android开发 开发者
Android开发之OpenGL的画笔工具GL10
这篇文章简述了OpenGL通过GL10进行三维图形绘制,强调颜色取值范围为0.0到1.0,背景和画笔颜色设置方法;介绍了三维坐标系及与之相关的旋转、平移和缩放操作;最后探讨了坐标矩阵变换,包括设置绘图区域、调整镜头参数和改变观测方位。示例代码展示了如何使用这些方法创建简单的三维立方体。
15 1
Android开发之OpenGL的画笔工具GL10
|
25天前
|
Android开发
Android开发小技巧:怎样在 textview 前面加上一个小图标。
Android开发小技巧:怎样在 textview 前面加上一个小图标。
12 0
|
5月前
Visual Studio Code开发常用的工具栏选项,查看源码技巧以及【vscode常用的快捷键】
Visual Studio Code开发常用的工具栏选项,查看源码技巧以及【vscode常用的快捷键】
245 0
|
6月前
|
API
使用 Visual Studio 开发 CS 的 BOF
使用 Visual Studio 开发 CS 的 BOF
|
6月前
|
开发框架 .NET 数据库
asp.net企业费用报销管理信息系统VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio
asp.net 企业费用报销管理信息系统是一套完善的web设计管理系统,系统具有完整的源代码和数据库,系统主要采用B/S模式开发。开发环境为vs2010,数据库为sqlserver2008,使 用c#语言开发 应用技术:asp.net c#+sqlserver 开发工具:vs2010 +sqlserver
49 0