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

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

<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设置全局颜色

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));}

  运行效果 如下

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

更多相关文章

  1. Android(安卓)布局的属性
  2. Android调用系统设置,Android调用系统设置中的某个设置
  3. Android(安卓)布局属性大全
  4. EditText属性
  5. android软键盘挤压界面的问题解决方法
  6. android游戏开发课程layout_…
  7. view属性大全
  8. 【Android】使用MediaCodec硬编码实现视频直播推流端(一)
  9. android textview 行间距

随机推荐

  1. 解决Android(安卓)Logcat不打印信息
  2. android Preference视图的使用
  3. HP TouchPad & Android
  4. Android(安卓)5-6月新的开源库
  5. Android10的WIFI 名称读取为空解决
  6. android调用java的web service接口
  7. Android(安卓)对话框(Dialog)大全 建立你
  8. Android(安卓)设置View点击区域
  9. Android(安卓)屏幕分辨率适配原理
  10. 重画Progressbar的进度