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实训案例(八)--单机五子棋游戏,自定义棋盘,线条,棋子,游戏逻辑,游戏状态存储,再来一局 阿法狗让围棋突然就被热议了,鸿洋大神也顺势出了篇五子棋单机游戏的视频,我看到了就像膜拜膜拜,就 ...
随机推荐
- Selenium2学习-019-WebUI自动化实战实例-017-获取浏览器类型
Web UI 自动化脚本分布执行过程中有时候需要获取浏览器的相关信息,此文给出了一个简略获取浏览器类型的方法,敬请各位小主们参阅.若有不足之处,敬请大神指正,不胜感激! 闲话少述,上码. /** * ...
- 关于ajax的异步通信之异步
我有这样一个js函数 function add (){ $ajax({ url:"xxxxxx", data:""xxxxx", dataType:& ...
- [转]详细介绍java中的数据结构
详细介绍java中的数据结构 本文介绍的是java中的数据结构,本文试图通过简单的描述,向读者阐述各个类的作用以及如何正确使用这些类.一起来看本文吧! 也许你已经熟练使用了java.util包里面的各 ...
- 文明3地图之二-大n型地图
存档文件:http://files.cnblogs.com/files/xiandedanteng/civ3bigN20160214.rar 地图: 简介: 这份地图几乎没有岛屿,整块大陆都连在一起像 ...
- ionic一些常见问题及方法(网页链接式)
ionic 进入二级目录以后隐藏底部导航栏(tabs) http://blog.csdn.net/shenshucong520/article/details/48287811ionic三级目录乃至多 ...
- Java Synchronized的用法
synchronized是Java中的关键字,是一种同步锁.它修饰的对象有以下几种: 1. 修饰一个代码块,被修饰的代码块称为同步语句块,其作用的范围是大括号{}括起来的代码,作用的对象是调用这个代码 ...
- C#读写BitMap及颜色相乘
C#读写BitMap及颜色相乘 private Bitmap ReadBitMapAndMultipy(Bitmap bitmap0) { int x1width = bitmap0.Width; i ...
- iOS UICollectionView之-(水平滚动)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- appcon 图标打包
ERROR ITMS-90022: "Missing required icon file. The bundle does not contain an app icon for iPho ...
- linux_x86_64 blat安装
blatSrc35.zip下载地址:http://users.soe.ucsc.edu/~kent/src/ 对于下载好的源代码安装包blatSrc35.zip,需进行编译,安装过程如下: 1.用un ...