首页 > 移动平台 > 详细

android手电筒开发

时间:2014-03-02 13:43:25      阅读:577      评论:0      收藏:0      [点我收藏+]

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

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

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

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

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

  运行效果 如下

bubuko.com,布布扣

 

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

android手电筒开发,布布扣,bubuko.com

android手电筒开发

原文:http://www.cnblogs.com/athook/p/3575281.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!