Android SDK 开发范例大全---3.2更改手机窗口画面底色
2015-11-30 19:02
507 查看
在之前的范例运行结果中,窗口的底色一律是“深黑色”,这是由于深黑色是SDK默认的颜色,如果更改Activity里的窗口颜色,有许多方法,最简单的方法就是将颜色色码事先在drawable当中,当程序onCreate创建时,就可以加载预先定义的画面颜色。
此范例程序的设计方式是在drawable里指定Layout的后台(Background)为白色,但这里的白色(色码#FFFFFF)是预先定义在drawable,当程序运行时,后台就会变成白色。
这是指定Activity Layout后台颜色的最简单方法。
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/myTextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:text="@string/hello" />
</LinearLayout>
/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">请访问戴维的博客: http//jumpin.cc</string>
<string name="app_name">Helloworld</string>
<drawable name="white">#FFFFFF</drawable>
</resources>
/src/com.helloworld/HellloWorldActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloworldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
此范例程序的设计方式是在drawable里指定Layout的后台(Background)为白色,但这里的白色(色码#FFFFFF)是预先定义在drawable,当程序运行时,后台就会变成白色。
这是指定Activity Layout后台颜色的最简单方法。
/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/white"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/myTextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:text="@string/hello" />
</LinearLayout>
/res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">请访问戴维的博客: http//jumpin.cc</string>
<string name="app_name">Helloworld</string>
<drawable name="white">#FFFFFF</drawable>
</resources>
/src/com.helloworld/HellloWorldActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloworldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
相关文章推荐
- Android FTP服务器搭建与文件上传及下载
- Android实现接口方式注册监听器
- Android系统中GC什么情况下会出现内存泄露呢?
- Android中Task任务栈的分配
- 对android虚拟机的理解,包括内存管理机制垃圾回收机制。dalvik和art区别
- 关于Android中使用SVG特性的探索与总结
- android:intnet
- Android兼容性问题 -- WebP格式图片解码失败
- Android 百度地图定位指针(系列2)
- android studio 编译运行报错
- Android 图片缓存处理
- 【Android】用Studio完成多设备多分辨率的适配
- 百度地图Android SDK报错:Error inflating class com.baidu.mapapi.map.MapView
- Android StartActivityForResult两个Activity相互跳转传递消息
- android测试之四:Android设备上的Benckmark测试概述
- android输入判定
- 一个Android Service小例子
- Android---MVP设计模式高级(三)
- Android---MVP设计模式中级(二)
- Android的Sqlite中DateTime类型数据的存取问题