最近学习android开发,记录学习过程,分享一写小案例

一. 如下先设置好布局文件

  1. <TextView
  2. android:id="@+id/textView1"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:layout_alignParentTop="true"
  6. android:layout_centerHorizontal="true"
  7. android:layout_marginTop="59dp"
  8. android:text="欢迎使用"
  9. android:textSize="40sp" />
  10.  
  11. <Button
  12. android:id="@+id/button1"
  13. android:onClick="clickRed"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_alignParentLeft="true"
  17. android:layout_centerVertical="true"
  18. android:text="红"
  19. />
  20.  
  21. <Button
  22. android:id="@+id/button2"
  23. android:onClick="clickGreen"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:layout_alignBaseline="@+id/button1"
  27. android:layout_alignBottom="@+id/button1"
  28. android:layout_centerHorizontal="true"
  29. android:text="绿"
  30. />
  31.  
  32. <Button
  33. android:id="@+id/button3"
  34. android:onClick="clickBlue"
  35. android:layout_width="wrap_content"
  36. android:layout_height="wrap_content"
  37. android:layout_alignBaseline="@+id/button2"
  38. android:layout_alignBottom="@+id/button2"
  39. android:layout_alignRight="@+id/textView1"
  40. android:text="蓝"
  41. />

  二 关键java代码 设置用getWindow().setBackgroundDrawable设置全局颜色

  1. public void clickRed(View view) {
  2. getWindow().setBackgroundDrawable(new ColorDrawable(Color.RED));
  3. }
  4.  
  5. public void clickBlue(View view) {
  6. getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLUE));
  7.  
  8. }
  9.  
  10. public void clickGreen(View view) {
  11. getWindow().setBackgroundDrawable(new ColorDrawable(Color.GREEN));
  12. }

  运行效果 如下

源码在这里 喜欢的拿去研究 点击下载

android手电筒开发的更多相关文章

  1. android平台手电筒开发源代码

    android平台手电筒开发源代码,AndroidManifest.xml文件的入口是startapp,这个文件没上传上来,大家可以自己写. 1. [代码]android 1 2 3 4 5 6 7 ...

  2. Android N开发 你需要知道的一切

    title: Android N开发 你需要知道的一切 tags: Android N,Android7.0,Android --- 转载请注明出处:http://www.cnblogs.com/yi ...

  3. Android游戏开发实践(1)之NDK与JNI开发03

    Android游戏开发实践(1)之NDK与JNI开发03 前面已经分享了两篇有关Android平台NDK与JNI开发相关的内容.以下列举前面两篇的链接地址,感兴趣的可以再回顾下.那么,这篇继续这个小专 ...

  4. Android游戏开发实践(1)之NDK与JNI开发01

    Android游戏开发实践(1)之NDK与JNI开发01 NDK是Native Developement Kit的缩写,顾名思义,NDK是Google提供的一套原生Java代码与本地C/C++代码&q ...

  5. Android游戏开发实践(1)之NDK与JNI开发02

    Android游戏开发实践(1)之NDK与JNI开发02 承接上篇Android游戏开发实践(1)之NDK与JNI开发01分享完JNI的基础和简要开发流程之后,再来分享下在Android环境下的JNI ...

  6. 【转】Android 底层开发的几点

    我干了3年Android sdk开发,觉得到了瓶劲没法更进一步,于是花了一年多点时间,大概摸到点门径.根据前辈的经验,Android底层完全入门需要两年. 先说下我的入门过程:第零步,下载源码,我下的 ...

  7. 《Android NFC 开发实战详解 》简介+源码+样章+勘误ING

    <Android NFC 开发实战详解>简介+源码+样章+勘误ING SkySeraph Mar. 14th  2014 Email:skyseraph00@163.com 更多精彩请直接 ...

  8. Android安全开发之安全使用HTTPS

    Android安全开发之安全使用HTTPS 1.HTTPS简介 阿里聚安全的应用漏洞扫描器中有证书弱校验.主机名弱校验.webview未校验证书的检测项,这些检测项是针对APP采用HTTPS通信时容易 ...

  9. Android安全开发之通用签名风险

    Android安全开发之通用签名风险 作者:伊樵.舟海.呆狐@阿里聚安全 1 通用签名风险简介 1.1 Android应用签名机制 阿里聚安全漏洞扫描器有一项检测服务是检测APP的通用签名风险.And ...

随机推荐

  1. linux 命令行更新sdk

    ./android list sdk --proxy-host android-mirror.bugly.qq.com --proxy-port 8080 --no-ui -a -s ./androi ...

  2. UITableView 小节-备

    UITableView 让列表自动滑动(定位)到某一行 NSIndexPath*scrollIndexPath = [NSIndexPathindexPathForRow:10inSection:0] ...

  3. Android实现三级联动下拉框 下拉列表spinner

    Android实现(省.市.县)三级联动下拉框 下拉列表spinner 转载请注明出处: http://www.goteny.com/articles/2013/11/46.html http://w ...

  4. WPF 自己动手来做安装卸载程序

    原文:WPF 自己动手来做安装卸载程序 前言 说起安装程序,这也许是大家比较遗忘的部分,那么做C/S是小伙伴们,难道你们的程序真的不需要一个炫酷的安装程序么? 声明在先 本文旨在教大家以自己的方式实现 ...

  5. SQL查询优化

    在数据库SQL性能优化中,查询优化所占比较高.select调优基本还是比较耗时的.所以我整理了一些提示.每当我在写查询语句的时候,总会看看是否满足这些提示清单. 1.要为WHERE 和JOIN后面的字 ...

  6. 为何某些公司不允许使用C++ STL?

    说几个STL的缺点吧,虽然都是在比较极端的情况下出现,但是对于一些大项目还是会遇到的 1. 代码膨胀问题每一个实例化过的模板类,都会膨胀出一份独立的代码,比如std::vector<std::s ...

  7. YII 事件event和行为Behavior

    To declare an event in your CComponent child class, you should add a method with aname starting with ...

  8. Effective C++笔记(一)——条款26-29

    条款26:尽可能延后变量定义式的出现时间 为何要尽量延后? 当程序中途跳出而导致变量未被使用,但是必须进行构造和析构. 最佳初始化变量 直接在构造时指定初值比构造之后再赋值效率高(条款4) ... s ...

  9. sigaction函数的使用

    sigaction函数的功能是检查或修改与指定信号相关联的处理动作(可同时两种操作). 他是POSIX的信号接口,而signal()是标准C的信号接口(如果程序必须在非POSIX系统上运行,那么就应该 ...

  10. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAApcAAAB3CAIAAADZ1fxtAAAbFElEQVR4nO2dzbHDOo6FHY9S0WqqZt