将径向渐变设置为窗口背景

时间:2011-08-21 14:58:09

标签: android background window drawable gradient

我有以下的gradient_bg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:type="radial"
        android:gradientRadius="200"
        android:startColor="#666666"
        android:endColor="#AAAAAA"
        />
</shape>

我想将此渐变用作我的应用程序的android:windowBackground设置。然后,应用程序将在其上面具有透明背景的几个视图。

我尝试使用以下方法直接应用此渐变:

android:windowBackground="@drawable/gradient_bg"
在我的应用程序清单中,然后将scrollview背景设置为透明,但我只是获得默认的黑色背景。

我将如何实现这一结果?我特别不想将背景应用于scrollview。

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:6)

另一种方法可能是创建一个主题(在values / styles.xml中):

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="windowbg" parent="android:Theme">
        <item name="android:windowBackground">@drawable/rectangle</item>
    </style>
</resources>

现在您可以将此主题添加到您的活动/应用程序中,如下所示:

android:theme="@style/windowbg"

答案 1 :(得分:0)

尝试从形状中制作位图。因此,创建与您的形状相关的antoher xml。一些例子:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/background"
        android:tileMode="repeat"/>
相关问题