android实操--练习1
这两天有空,打算把一些文档整理一下,快要考试了,找一些简单的例子来做做,重温安卓的知识.
下面是第一个练习:

实现很简单,下面我们来看看:
- 首先新建一个安卓项目Demo1
- 接着是界面的布局(包括activity_main.xml/strings.xml)

- 最后是实际的功能的实现

代码预览:
------------------------布局文件----------------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/showWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/GreenBtn"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/BlueBtn"
android:layout_marginTop="17dp"
android:text="@string/ShowWordText"
android:textStyle="bold" />
<Button
android:id="@+id/GreenBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/showWord"
android:layout_marginLeft="22dp"
android:layout_marginTop="28dp"
android:gravity="left|center_vertical|center_horizontal"
android:text="@string/GreenBtnText" />
<Button
android:id="@+id/BlueBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/YellowBtn"
android:layout_alignBottom="@+id/YellowBtn"
android:layout_toRightOf="@+id/YellowBtn"
android:gravity="left|center_vertical|center_horizontal"
android:text="@string/BlueBtnText" />
<Button
android:id="@+id/YellowBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/GreenBtn"
android:layout_alignBottom="@+id/GreenBtn"
android:layout_toRightOf="@+id/GreenBtn"
android:gravity="left|center_vertical|center_horizontal"
android:text="@string/YellowBtnText" />
</RelativeLayout>
----------------------------功能实现--------------------
package com.example.demo1;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.graphics.Color;
public class MainActivity extends Activity implements OnClickListener{
TextView tv_show=null;
Button greenBtn=null;
Button blueBtn=null;
Button yellowBtn=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_show=(TextView)findViewById(R.id.showWord);
greenBtn=(Button)findViewById(R.id.GreenBtn);
blueBtn=(Button)findViewById(R.id.BlueBtn);
yellowBtn=(Button)findViewById(R.id.YellowBtn);
greenBtn.setOnClickListener(this);
blueBtn.setOnClickListener(this);
yellowBtn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.GreenBtn:
tv_show.setTextColor(Color.GREEN);
break;
case R.id.BlueBtn:
tv_show.setTextColor(Color.BLUE);
break;
case R.id.YellowBtn:
tv_show.setTextColor(Color.YELLOW);
break;
default:
break;
}
}
}
android实操--练习1的更多相关文章
- android实操--练习2
练习2是实现一个计算器的功能:可以加减乘除:可以倒退,可以清空文本. 下面是效果展示: -----------------------布局------------------------------- ...
- Appium常用Api实操
本文是基于python语言在android上实操的,仅记录(忽略排版~~~) 会不时更新的: from appium import webdriver from selenium.webdriver. ...
- ABP入门系列(1)——学习Abp框架之实操演练
作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...
- 号外号外:9月13号《Speed-BI云平台案例实操--十分钟做报表》开讲了
引言:如何快速分析纷繁复杂的数据?如何快速做出老板满意的报表?如何快速将Speed-BI云平台运用到实际场景中? 本课程将通过各行各业案例背景,将Speed-BI云平台运用到实际场景中 ...
- Mysql MHA(GTID)配置(实操)
实现环境 centos6.7 MYSQL5.6.36 主:192.168.1.191 从1:192.168.1.145 从2:192.168.1.146 监测:放在从2上 192.168.1.146 ...
- Selenium之unittest测试框架详谈及实操
申明:本文是基于python3.x及selenium3.x. unittest,也可以称为PyUnit,可以用来创建全面的测试套件,可以用于单元自动化测试(模块).功能自动化测试(UI)等等. 官方文 ...
- unittest测试框架详谈及实操(二)
类级别的setUp()方法与tearDown()方法 在实操(一)的例子中,通过setUp()方法为每个测试方法都创建了一个Chrome实例,并且在每个测试方法执行结束后要关闭实例.是不是觉得有个多余 ...
- Android实训案例(九)——答题系统的思绪,自己设计一个题库的体验,一个思路清晰的答题软件制作过程
Android实训案例(九)--答题系统的思绪,自己设计一个题库的体验,一个思路清晰的答题软件制作过程 项目也是偷师的,决心研究一下数据库.所以写的还是很详细的,各位看官,耐着性子看完,实现结果不重要 ...
- Android实训案例(八)——单机五子棋游戏,自定义棋盘,线条,棋子,游戏逻辑,游戏状态存储,再来一局
Android实训案例(八)--单机五子棋游戏,自定义棋盘,线条,棋子,游戏逻辑,游戏状态存储,再来一局 阿法狗让围棋突然就被热议了,鸿洋大神也顺势出了篇五子棋单机游戏的视频,我看到了就像膜拜膜拜,就 ...
随机推荐
- recordcount
rs.recordcount 有时不能取到数,这时 要更改游标为客户端游标 .
- c#上传文件(一)使用 .net 控件上传文件
1.html代码: <body> <form id="form1" runat="server"> <div> <as ...
- c# 并行运算
c# 并行运算 1. Parallel.INVOKE() 看实例: private static Stopwatch watch = new Stopwatch(); private static v ...
- UVA 10127题目描述
Given any integer 0 ≤ n ≤ 10000 not divisibleby 2 or 5, some multiple of n is a number whichin decim ...
- Eclipse常用设置(转)
http://jingyan.baidu.com/article/3065b3b6efa9d7becff8a4c6.html 用惯了VS,再回过去用Eclipse真是一件痛苦的事.so,在这里记录下使 ...
- centos 下 django 1.8 配置好后 admin 后台无法显示 样式解决办法
解决前 解决命令 [root@ayibang-server static]# cat /etc/nginx/conf.d/office_djaong_uvpv.conf server { listen ...
- 关于OC语法的公开和私有的讨论
关于OC语法的公开和私有的讨论 OC语法中,类的.h文件向外面暴露类的功能/方法接口,其中定义的属性/方法/协议/类别/类扩展都属于公开的,但实例变量要看限定词(@protected/@public/ ...
- CAD出图
今天帮着客户输出图纸,用打印命令,设置打印参数,选择dwg到pdf打印机.设置图纸大小等参数 CAD满图纸输出 按照比例尺输出 plot,一般图纸绘制是已经有一个比例尺,所以按照1:1输出,如果图纸是 ...
- openId 列表
http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html 根据OpenID列表群发[订阅号不可用,服务号认证后可用] ...
- javascript 字符串相关知识汇总
① charAt(): 选中字符串内第几个元素 <script> var str="1234567389"; alert( str.charAt(1) ); // 2 ...