
在进行几次安卓入门的界面界面编写后,我打算开始进行一系列比较系统的学习。所以今天的学习就从比较简单的东西入手。
(一)应用程序组件| 组件 | 描述 |
|---|---|
| ActivitIEs | 描述UI,并且处理用户与机器屏幕的交互。 |
| Services | 处理与应用程序关联的后台 *** 作。 |
| broadcast Receivers | 处理AndroID *** 作系统和应用程序之间的通信。 |
| Content ProvIDers | 处理数据和数据库管理方面的问题。 |
| 项目 | Value |
|---|---|
| Fragments | 代表活动中的一个行为或者一部分用户界面。 |
| VIEws | 绘制在屏幕上的UI元素,包括按钮,列表等。 |
| Layouts | 控制屏幕格式,展示视图外观的VIEw的继承。 |
| Intents | 组件间的消息连线。 |
| Resources | 外部元素,例如字符串资源、常量资源及图片资源等。 |
| Manifest | 应用程序的配置文件。 |
创建完成后,所得界面如图所示:
3.代码展示
1.activity_main.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:gravity="center" tools:context=".MainActivity"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/tvMessage" androID:textSize="25dp" androID:textcolor="#0000ff"/></linearLayout>2.AndroIDManifest.xml
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="net.nell.userlogin"> <application 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/theme.UserLogin"> <activity androID:name=".LoginActivity"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity androID:name=".MainActivity"> </activity> </application></manifest>3.activity_login.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="@drawable/background" androID:gravity="center" androID:padding="15dp" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/tvUserLogin" androID:layout_marginBottom="30dp" androID:text="@string/user_login" androID:textcolor="#ff00ff" androID:textSize="25sp"/> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:gravity="center_horizontal" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/tvUsername" androID:text="@string/username" androID:textcolor="#000000" androID:textSize="20sp"/> <EditText androID:layout_wIDth="150dp" androID:layout_height="wrap_content" androID:ID="@+ID/edtUsername" androID:ems="10" androID:hint="@string/input_username" androID:singleline="true"/> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:gravity="center_horizontal" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/tvPassword" androID:text="@string/password" androID:textcolor="#000000" androID:textSize="20sp"/> <EditText androID:layout_wIDth="150dp" androID:layout_height="wrap_content" androID:ems="10" androID:hint="@string/input_password" androID:ID="@+ID/edtPassword" androID:inputType="textPassword" androID:singleline="true"/> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:layout_margintop="30dp" androID:gravity="center_horizontal" androID:orIEntation="horizontal"> <button androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/btnLogin" androID:paddingRight="30dp" androID:paddingleft="30dp" androID:text="@string/login" androID:textSize="20sp"/> <button androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:ID="@+ID/btnCancel" androID:paddingleft="30dp" androID:paddingRight="30dp" androID:text="@string/cancel" androID:textSize="20sp"/> </linearLayout></linearLayout>4.strings.xml
// An highlighted blockvar foo = 'bar';5.LoginActivity
package net.nell.userlogin;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.Widget.button;import androID.Widget.EditText;import androID.Widget.Toast;import androIDx.appcompat.app.AppCompatActivity;public class LoginActivity extends AppCompatActivity { private EditText edtUsername; private EditText edtPassword; private button btnLogin; private button btnCancel; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_login); edtUsername = findVIEwByID(R.ID.edtUsername); edtPassword = findVIEwByID(R.ID.edtPassword); btnCancel = findVIEwByID(R.ID.btnCancel); btnLogin = findVIEwByID(R.ID.btnLogin); btnLogin.setonClickListener(new VIEw.OnClickListener(){ @OverrIDe public voID onClick(VIEw v) { String strUsername = edtUsername.getText().toString().trim(); String strPassword = edtPassword.getText().toString().trim(); if (strUsername.equals("admin") && strPassword.equals("admin")){ Toast.makeText(LoginActivity.this,"恭喜,用户名与密码正确!",Toast.LENGTH_SHORT).show();; }else { Toast.makeText(LoginActivity.this,"遗憾,用户名或密码错误",Toast.LENGTH_SHORT).show(); } } }); btnCancel.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { finish(); } }); }}4.效果展示(五)案例演示(二)1.效果展示2.代码展示activity_main.xml
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context=".MainActivity" androID:orIEntation="vertical"><linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="5" androID:textSize="80dp" /> <linearLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="6" androID:orIEntation="vertical" androID:padding="10dp"> <linearLayout androID:layout_wIDth="240dp" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-19 17:50:35" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="admin" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-19" androID:textcolor="@color/black" androID:textSize="25dp" /> </linearLayout> </linearLayout> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="已审" androID:textSize="25dp" androID:layout_gravity="center_vertical"/> <TextVIEw androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:background="#c0c0c0" androID:text="审核" androID:textSize="35dp" androID:layout_gravity="center_vertical" androID:gravity="center"/> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="6" androID:textSize="80dp" /> <linearLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="6" androID:orIEntation="vertical" androID:padding="10dp"> <linearLayout androID:layout_wIDth="240dp" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-19 17:50:56" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="admin" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-19" androID:textcolor="@color/black" androID:textSize="25dp" /> </linearLayout> </linearLayout> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="未审" androID:textSize="25dp" androID:layout_gravity="center_vertical"/> <TextVIEw androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:background="#c0c0c0" androID:text="审核" androID:textSize="35dp" androID:layout_gravity="center_vertical" androID:gravity="center"/> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="7" androID:textSize="80dp" /> <linearLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="6" androID:orIEntation="vertical" androID:padding="10dp"> <linearLayout androID:layout_wIDth="240dp" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-20 18:13:41" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="admin" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-20" androID:textcolor="@color/black" androID:textSize="25dp" /> </linearLayout> </linearLayout> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="未审" androID:textSize="25dp" androID:layout_gravity="center_vertical"/> <TextVIEw androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:background="#c0c0c0" androID:text="审核" androID:textSize="35dp" androID:layout_gravity="center_vertical" androID:gravity="center"/> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="8" androID:textSize="80dp" /> <linearLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="6" androID:orIEntation="vertical" androID:padding="10dp"> <linearLayout androID:layout_wIDth="240dp" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-20 18:13:56" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="admin" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-20" androID:textcolor="@color/black" androID:textSize="25dp" /> </linearLayout> </linearLayout> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="未审" androID:textSize="25dp" androID:layout_gravity="center_vertical"/> <TextVIEw androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:background="#c0c0c0" androID:text="审核" androID:textSize="35dp" androID:layout_gravity="center_vertical" androID:gravity="center"/> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="9" androID:textSize="80dp" /> <linearLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="6" androID:orIEntation="vertical" androID:padding="10dp"> <linearLayout androID:layout_wIDth="240dp" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-21 10:25:35" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="admin" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-21" androID:textcolor="@color/black" androID:textSize="25dp" /> </linearLayout> </linearLayout> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="未审" androID:textSize="25dp" androID:layout_gravity="center_vertical"/> <TextVIEw androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:background="#c0c0c0" androID:text="审核" androID:textSize="35dp" androID:layout_gravity="center_vertical" androID:gravity="center"/> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="10" androID:textSize="80dp" /> <linearLayout androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="6" androID:orIEntation="vertical" androID:padding="10dp"> <linearLayout androID:layout_wIDth="240dp" androID:layout_height="wrap_content" androID:orIEntation="vertical"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-21 10:25:35" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="admin" androID:textcolor="@color/black" androID:textSize="25dp" /> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="2" androID:text="2014-02-21" androID:textcolor="@color/black" androID:textSize="25dp" /> </linearLayout> </linearLayout> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="未审" androID:textSize="25dp" androID:layout_gravity="center_vertical"/> <TextVIEw androID:layout_wIDth="120dp" androID:layout_height="120dp" androID:background="#c0c0c0" androID:text="审核" androID:textSize="35dp" androID:layout_gravity="center_vertical" androID:gravity="center"/> </linearLayout></linearLayout>以上便是今日的学习内容,虽然很简单,但是学习一门课程的重点还是在于基础。所以基础的建立对学习一门课程十分重要。
本次学习内容的重要来源资料如下:
链接: https://blog.csdn.net/howard2005/article/details/108648192.
链接: https://blog.csdn.net/howard2005/article/details/108753377.
链接: https://blog.csdn.net/howard2005/article/details/109461197.
以上是内存溢出为你收集整理的Android学习目录全部内容,希望文章能够帮你解决Android学习目录所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)