---
title: "android UI入门三 自定义背景样式"
author: "fokman"
date: "2012-08-01T15:23:36Z"
tags: []
categories: ["移动开发"]
slug: "android-ui"
draft: false
lastmod: "2012-08-01T15:23:36Z"
id: 1615678
url: "https://fokman.iteye.com/blog/1615678"
---

在android 开发应用中，大部份的开发人员都会使用背景图作为项目的背景，其实使用style.xml配置也可以实现比较漂亮的背景样式。

      在/drawable/下创建一个bg.xml 文件，用来定义项目的背景样式。

      文件内容如下：

     

     

```
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient
    android:startColor="#ffe5e9ed"
    android:endColor="#ffc3dae6"
    android:angle="270" />

</shape>
```

 定义一个渐变的轮廓，渐变的起始颜色和终止颜色。

在你的布局文件里面条用

 

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/bg" >

</LinearLayout>
```

定义样式文件可以更加灵活调整。