1.采用在布局文件中定义默认的背景颜色

  首先定义一个颜色的资源文件,Android中所有的资源文件都是以XML的样式定义的


<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="white">#ffffff</drawable>
</resources>

  其次,在布局文件中引用ID来访问

 

2.更改手机窗口画面底色--drawable定义颜色常数的方法2.更改手机窗口画面底色--drawable定义颜色常数的方法代码

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation
="vertical"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
android:background
="@drawable/white"
>
<TextView
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:text
="@string/hello"
/>
</LinearLayout>

 这样引用上面布局文件的Activity的背景就是白色的了,截图如下:2.更改手机窗口画面底色--drawable定义颜色常数的方法

 

2.可以通过当前基类对象得到资源文件引用,并通过View.setBackgroundDrawable(Drawable b)来设置背景颜色,具体用法如下:  

Resources resources = getBaseContext().getResources();

Drawable drawable = resources.getDrawable(R.drawable.white);

TextView tv = (TextView)findViewById(R.id.txt_name);

      tv.setBackgroundDrawable(drawable);

转载于:https://www.cnblogs.com/liqiangwaini/articles/1930286.html

相关文章:

  • 2021-08-12
  • 2022-01-19
  • 2022-01-20
  • 2022-12-23
  • 2022-01-01
  • 2022-12-23
  • 2021-07-04
猜你喜欢
  • 2021-12-18
  • 2021-12-18
  • 2021-12-18
  • 2021-10-20
  • 2021-04-14
  • 2021-11-16
  • 2021-11-22
相关资源
相似解决方案