您的位置 首页 golang

物联网实战教程3.2,安卓开发HelloActivity分析

物联网系列教程

一个很好的物联网(IoT)开发实战入门教程,图、文详细。供计算机、电子工程相关专业的在校生以及相关领域初学者、爱好者参考学习。涉及单片机、 上位机 、移动应用、服务器后台开发的知识,以及蓝牙4.0、以太网模块的使用实例。

物联网实战教程3.2,安卓开发HelloActivity分析

从本章开始,将要进入移动开发的世界——安卓开发。安卓程序需要基于面向对象的 java 语言进行开发,读者需要了解XML的使用,最好有过面向对象的基础,并且最好了解一下Java语言。另外,由于安卓是Google出品,请准备好梯子。

目录

第一部分:基础入门

第1项:单片机开发——Arduino

  • 1.1 Arduino开发环境搭建(往期文章)
  • 1.2 点亮一个Led(往期文章)
  • 1.3 PWM操作(往期文章)
  • 1.4 UART的使用(往期文章)
  • 第2项:上位机开发——.Net

  • 2.1 winform快速入门(往期文章)
  • 2.2 serialport控件使用(往期文章)
  • 第3项:移动开发——Android

  • 3.1 安卓开发环境搭建(上期文章)
  • 3.2 Hello Activity 分析( 本期文章
  • 3.3 LinearLayout与基本控件( 下期文章更新 ,两天更新一期)
  • 3.4 intent activity 的生命周期
  • 3.5 ListView与BaseAdapter
  • 3.6 Service学习
  • 3.7 Android权限机制
  • 3.8 BroadCastReciever学习
  • 第4项:后端开发——Golang

  • 4.1 go语言开发环境搭建
  • 4.2 go语言基础快速入门
  • 4.3 用go语言显示一个网页
  • 4.4 go语言web框架——gin
  • 4.5 部署go语言项目
  • 第二部分:案例学习

    第5项:蓝牙4.0案例——手机控制RGB灯颜色

  • 5.1 用串口控制RGB灯颜色
  • 5.2 用上位机控制RGB灯颜色
  • 5.3 蓝牙4.0简单介绍
  • 5.4 蓝牙4.0安卓例程源码阅读
  • 5.5 用安卓手机控制RGB灯颜色
  • 第6项:网络模块案例——温度采集系统开发

  • 6.1 Arduino温度传感器的使用
  • 6.2 ENC28J60模块的使用
  • 6.3 在网页上显示温度

  • 3.2 HelloActivity分析

    Android Studio目录结构

    我们重新进入Android Studio,就会自动进入之前的工程:HelloActivity。如果不想自动打开上一次的工程,可以点击File下的Settings,然后选择Appearance & Behavior下面的System Settings,然后把Reopen last project on startup勾选掉。

    物联网实战教程3.2,安卓开发HelloActivity分析

    我们看一下右侧的项目目录,可以看到除了渐变的配置文件外,有一个应用程序的目录。这个app目录叫一个模块,一个项目可以包含多个模块,我们现在当前是一个。会涉及到多模块的使用,读者可以自行百度。)

    物联网实战教程3.2,安卓开发HelloActivity分析

    下面展开app目录,这里一个共有三个文件夹,清单(配置文件),java(源码),res(资源文件)。

    物联网实战教程3.2,安卓开发HelloActivity分析

    下面,开始分别讲解每个文件夹的作用和功能。

    程序的入口:AndroidManifest.xml分析

    首先,我们打开manifests文件夹,这里只有一个AndroidManifest.xml。

     <?xml版本= “ 1.0 ”编码= “ utf-8 ”?>
    <清单 xmlns :android = “  ”
        包= “ com.example.kalen.helloactivity ” >
    
        <应用
            的android :allowBackup = “真”
            机器人:图标= “ @ mip映射/ ic_launcher ”
            机器人:标签= “ @串/ APP_NAME ”
            机器人:roundIcon = “ @ mip映射/ ic_launcher_round ”
            机器人:supportsRtl = “真”
            机器人:主题= “ @ style / AppTheme ” >
            <活动 android :名称= “ .MainActivity ” >
                <意图过滤器>
                    < action  android :name = “ android.intent.action.MAIN ” />
    
                    < category  android :name = “ android.intent.category.LAUNCHER ” />
                </ intent-filter >
            </活动>
        </ application >
    
    </清单>  

    我们可以看到最外层是一个manifest标签,里面显示了包名是“ com.example.kalen.helloactivity”。在manifest标签里面是一个应用标签,也就是我们的Android应用,这里有一些属性,如图标,标签,都是设置应用配置的。形如@xxx/xxx的都是从res文件夹下面读取的。这样说,我们要改应用的名称,可以打开res下的值文件夹的strings.xml,然后修改app_name的名字。

    物联网实战教程3.2,安卓开发HelloActivity分析

    再运行应用安装到模拟器的时候,可以看到安装的app的名字就改变了。

    物联网实战教程3.2,安卓开发HelloActivity分析

    当然,也可以通过替换mipmap下的ic_launcher和ic_launcher_round来修改图标,不过和修改字符串不同,我们可以直接在电脑上打开HelloActivityappsrcmainres目录,可以看到有很多个以mipmap开始的目录,后面的代表不同的尺寸。我们需要设计多个尺寸的图标以适应不同预设的手机。

    物联网实战教程3.2,安卓开发HelloActivity分析

    另外,我们也可以改变应用的主题(style / AppTheme),打开下面的values里的styles.xml。

     <!-基础应用程序主题。-> 
    <样式 名称= “ AppTheme ”  parent = “ Theme.AppCompat.Light.DarkActionBar ” >
         <!-在此处自定义主题。-> 
        <项目 名称= “ colorPrimary ” > @ color / colorPrimary </ item >
        < item  name = “ colorPrimaryDark ” > @ color / colorPrimaryDark </ item >
        < item  name = “ colorAccent ” > @ color / colorAccent </ item >
    </ style >  

    可以看到此处设置了三种颜色。我们可以修改colors.xml的colorPrimary,colorPrimaryDark,colorAccent更改这几种颜色。此类我们可以把colorPrimary设置为#000000(黑色)。

    物联网实战教程3.2,安卓开发HelloActivity分析

    再运行app,app顶部的一栏就变成了黑色。

    物联网实战教程3.2,安卓开发HelloActivity分析

    看完了application标签的几个属性,我们来看看它的子标签:activity。这里最初有一个名字是“ .MainActivity”,这是一个相对的路径(相对于manifest标签下的包装:“ com.example .kalen.helloactivity”)。这个活动标签指向的是:com.example.kalen.helloactivity.MainActivity。

    物联网实战教程3.2,安卓开发HelloActivity分析

    另外,在活动下面有一个intent-filter标签。intent-filter里面有一个动作和类别,名称属性一个是“ android.intent.action.MAIN”,还有一个是“ android.intent.category.LAUNCHER”,通过名字可以抛光,这个其实就是指示启动其中活动的,这样的标签一个应用只能有一个,MainActivity就是我们程序的入口。

    MainActivity.java分析

    下面看看代码,打开MainActivity.java文件。发现MainActivity.java内只有一个方法: onCreate

     公共 类 MainActivity 扩展了 AppCompatActivity {
    
        @Override
        受保护的 void  onCreate(Bundle  savedInstanceState){
             super 。onCreate(savedInstanceState);
            的setContentView(ř 。布局。 activity_main);
        }
    }  

    在onCreate方法里面,除了调用父类的方法,也只有一行代码,setContentView,翻译过来就是设置内容视图,也就是显示什么内容。

    那么R.layout.activity_main是什么?可以看到并没有导入任何R文件。我们下面摁住ctrl键,鼠标滑动到layout上面。

    物联网实战教程3.2,安卓开发HelloActivity分析

    可以看到这里显示出了一个0x7f04001b,看起来像一个地址一样。下面,我们再次摁住ctrl键,然后点击activity_main,看看这个是什么东西。可以看到我们替换到了res下的layout的activity_main .xml里面。

    物联网实战教程3.2,安卓开发HelloActivity分析

    现在应该明白了,这个R文件实际上就是和res的一个对应,把res的每个变量都生成一个地址。等等我们输入R.color可以看到colors.xml的一种颜色。

    物联网实战教程3.2,安卓开发HelloActivity分析

    再来看看activity_main.xml,我们可以看到最外面有一个android.support.constraint.ConstraintLayout,是一种布局格式。里面有一个TextView,里面的文本属性写着“ Hello World”,和app上面的Hello世界相对应。

    物联网实战教程3.2,安卓开发HelloActivity分析

    第二个活动

    了解了Activity的布局,下面我们创建第二个Activity,并尝试以第二个Activity作为启动项。右击com.example.kalen.helloactivity,选择创建一个Java Class。

    物联网实战教程3.2,安卓开发HelloActivity分析

    类的名字设置为SecondActivity,点击回车之后,就会生成一个空的类,下面让它继承AppCompatActivity,并在Create方法上进行重写。

     包 com.example.kalen.helloactivity ;
    
    导入 android.os.Bundle ;
    导入 android.support.v7.app.AppCompatActivity ;
    
    公共 类 SecondActivity 扩展了 AppCompatActivity {
    
        @Override
        受保护的 void  onCreate(Bundle  savedInstanceState){
             super 。onCreate(savedInstanceState);
        }
    }  

    接着我们在layout目录下创建一个布局XML。

    物联网实战教程3.2,安卓开发HelloActivity分析

    命名为activity_second,然后单击Finish。

    物联网实战教程3.2,安卓开发HelloActivity分析

    先选择下面的代码,在LinearLayout里面添加一个TextView或显示一段文字。

     <?xml版本= “ 1.0 ”编码= “ utf-8 ”?>
    < LinearLayout  xmlns :android = “  ”
         android :layout_width = “ match_parent ”
         android :layout_height = “ match_parent ” >
    
        < TextView 
            android :layout_width = “ wrap_content ”
             android :layout_height = “ wrap_content ”
             android :text = “第二个活动” />
    
    </ LinearLayout >  

    接着,就可以在onCreate方法中添加setContentView(R.layout.activity_second);了。

    最后,我们在AndroidManifest.xml里面注册了SecondActivity,并把MainActivity的intent-filter添加到了SecondActivity下面。

         <申请
            android:allowBackup =“ true”
            android:icon =“ @ mipmap / ic_launcher”
            android:label =“ @ string / app_name”
            android:roundIcon =“ @ mipmap / ic_launcher_round”
            android:supportsRtl =“ true”
            android:theme =“ @ style / AppTheme”>
            <activity android:name =“。MainActivity”> </ activity>
            <activity android:name =“。SecondActivity”>
                <意图过滤器>
                    <action android:name =“ android.intent.action.MAIN” />
                    <category android:name =“ android.intent.category.LAUNCHER” />
                </ intent-filter>
            </ activity>
        </ application>  

    这时候,运行程序,就可以显示SecondActivity的内容了。

    物联网实战教程3.2,安卓开发HelloActivity分析


    下期更新预告:

    第1部分:单片机开发——Arduino

  • 第2项:上位机开发——.Net

  • 第3项:移动开发——Android

  • 3.2 HelloActivity分析( 本期文章
  • 3.3 LinearLayout与基本控件( 下期更新这部分内容
  • 三连加关注,往后不迷路

    往期哪里搞,上面找一找

    文章来源:智云一二三科技

    文章标题:物联网实战教程3.2,安卓开发HelloActivity分析

    文章地址:https://www.zhihuclub.com/97013.shtml

    关于作者: 智云科技

    热门文章

    评论已关闭

    31条评论

    1. Storek KM, Gertsvolf NA, Ohlson MB, Monack DM 2015 cGAS and Ifi204 cooperate to produce type I IFNs in response to Francisella infection Shortly before my 39th birthday, when I was taking a shower, I felt a lump about the size and shape of a pea in my right breast

    2. com 20 E2 AD 90 20Asda 20Herbal 20Viagra 20 20Viagra 20Natural 20Farmacias 20Ahumada asda herbal viagra Assistant Chief Constable Drew Harris told the Policing Board on Thursday the substantive facts of case papers had been examined in 2010, including taking legal advice and consulting with the PPS

    3. breast next Neoplasm ti, ab, kw from 2008 to 2013, in Cochrane Reviews 5, before initiation of lymphatic development, traced most of the dermal LECs but with lower efficiency in the lumbar compared with the cervical skin

    4. Roger Poisson can still remember the first time he fudged a a breast cancer patient s medical record, on a day long ago in 1977, so she could be enrolled in a study even though she had missed the deadline by several days

    5. Bake in the oven for 12 to 15 minutes until cooked through Therapeutic Angiogenesis of Human Early Endothelial Progenitor Cells Is Enhanced by Thrombomodulin

    6. 5 in the JQJT tablets group compared with 28 Completely different from working with the arrogant French, Dassault has very strict control over its own software

    7. It is always prudent to run standard blood chemistry panels on your dog from time to time Miklowitz DJ

    8. Contemporary outcomes of metastatic breast cancer among 22, 000 women from the multicentre ESME cohort 2008 2016

    9. As for the declining nobles, the family high blood pressure article background is declining, and this noble style must not be lost

    10. Therefore low progesterone levels can be risky during pregnancy and progesterone supplements may be prescribed at various stages of pregnancy, not just the beginning Symptoms of hypoglycemia, increased mortality in ALS patients taking large doses of BCAAs

    11. It is important to note that Langerhans cells 46, 47 and high baseline expression of the high affinity IgE receptor FcОµRI ref

    12. Antibacterial therapy administered parenterally or orally has produced similar therapeutic benefits

    13. viagra clindamycin and benzoyl peroxide cream There are concerns about whether the economy is robustenough to cope and our suspicion is that the decision increasesthe pressure to ease monetary policy further, Tom Levinson, strategist at ING, wrote in a note

    14. Zydus and its affiliates accept no responsibility for the reliance on or use of any information contained herein It can be associated with red cell autoantibodies that are drug independent, that is, detected in vitro without adding drug or with drug dependent antibodies that only react in vitro in the presence of drug

    15. Place your feet up higher than your heart level when resting l NAME dose was the same as used by Banks and Oyekan 2 to block NOS activity in studies examining peroxisome proliferator activated receptor subtype О± agonist treated rats

    16. Bioelectrical impedance body composition analysis BIA is a non invasive method of fluid assessment which can provide estimates of total body, extracellular and intracellular water to allow the quantification of fluid overload 70

    17. By way of example and not limitation, carbon bonded heterocycles are bonded at position 2, 3, 4, 5, or 6 of a pyridine, position 3, 4, 5, or 6 of a pyridazine, position 2, 4, 5, or 6 of a pyrimidine, position 2, 3, 5, or 6 of a pyrazine, position 2, 3, 4, or 5 of a furan, tetrahydrofuran, thiofuran, thiophene, pyrrole or tetrahydropyrrole, position 2, 4, or 5 of an oxazole, imidazole or thiazole, position 3, 4, or 5 of an isoxazole, pyrazole, or isothiazole, position 2 or 3 of an aziridine, position 2, 3, or 4 of an azetidine, position 2, 3, 4, 5, 6, 7, or 8 of a quinoline or position 1, 3, 4, 5, 6, 7, or 8 of an isoquinoline I can t tell what tiny side effects are residual from the surgery into the chest wall, and what are from radiation my one breast is smaller than the other, I have a pretty big scar, I have 4 tiny little tattoos that I don t really like, my nipple is still swollen, and my chest gets super sore sometimes

    网站地图