登录  /  注册
首页 > php教程 > php手册 > 正文
【Android】第5章(1)常用基本控件--本章示例主界面
php中文网
发布: 2016-07-06 13:30:17
原创
727人浏览过

分类:C#、Android、VS2015; 创建日期:2016-02-06 这一章主要介绍Android简单控件的基本用法。本章源程序共有9个示例,这些示例都在同一个项目中。 项目名:ch05demos,项目模板:Blank App(Android) 运行主界面截图如下: 点击每行的示例项,即进入对应示

分类:C#、Android、VS2015;

创建日期:2016-02-06

这一章主要介绍Android简单控件的基本用法。本章源程序共有9个示例,这些示例都在同一个项目中。

项目名:ch05demos,项目模板:Blank App(Android)

运行主界面截图如下:

image

点击每行的示例项,即进入对应示例的页面。

1、在drawable文件夹下添加图片

添加的图片见下面的左图,也可以直接拖放图片到drawable文件夹下。

右图是各节例子实现后的纵向屏幕布局文件(layout文件夹)、横向屏幕布局文件(layout-land文件夹)、弹出菜单布局文件(menu文件夹)。这些都是在本章后续将要介绍的节中添加的。

image

2、主界面(Main.axml)

修改后的代码如下:

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listView1" />
LinearLayout>
登录后复制

3、主界面对应的活动文件(MainActivity.cs)

本章示例全部完成后MainActivity.cs的代码如下:

using System;
using Android.App;
using Android.Widget;
using Android.OS;
using ch05demos.SrcActivity;

namespace ch05demos
{
    [Activity(Label = "ch05demos", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        string[] items;

        PRotected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            items = new string[]
            {
                "Demo01EditText",
                "Demo02Login",
                "Demo03MultiResolution",
                "Demo04CheckBoxRadioButton",
                "Demo05Spinner",
                "Demo06SwitchAndRatingBar",
                "Demo07PopupMenu",
                "Demo08Gallery",
                "Demo09SeekBar"
            };
            ListView listView1 = FindViewById(Resource.Id.listView1);
            listView1.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);
            listView1.ItemClick += (s, e) =>
            {
                int index = e.Position + 1;
                switch(index)
                {
                    case 1:
                        StartActivity(typeof(Demo01EditText));
                        break;
                    case 2:
                        StartActivity(typeof(Demo02Login));
                        break;
                    case 3:
                        StartActivity(typeof(Demo03MultiResolution));
                        break;
                    case 4:
                        StartActivity(typeof(Demo04CheckBoxRadioButton));
                        break;
                    case 5:
                        StartActivity(typeof(Demo05Spinner));
                        break;
                    case 6:
                        StartActivity(typeof(Demo06SwitchAndRatingBar));
                        break;
                    case 7:
                        StartActivity(typeof(Demo07PopupMenu));
                        break;
                    case 8:
                        StartActivity(typeof(Demo08Gallery));
                        break;
                    case 9:
                        StartActivity(typeof(Demo09SeekBar));
                        break;
                }
            };
        }
    }
}
登录后复制

4、清单文件(AndroidManifest.xml)

在这个文件中只添加了一条内容:设置应用到所有页面的公用主题。

xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ch05demos.ch05demos" android:versionCode="1" android:versionName="1.0">
    <uses-sdk />
    <application android:label="ch05demos"
       android:theme="@android:style/Theme.DeviceDefault.Light">
application>
manifest>
登录后复制

从下一节开始,将分别介绍如何实现各个示例,以及这些示例涉及的相关概念。


来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学