Android背景漸層色效果,android背景漸層
Android設定背景色可以通過在res/drawable裡定義一個xml,如下:
[代碼]xml代碼:
1 |
<?xml version="1.0" encoding="utf-8"?> |
2 |
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
4 |
android:startColor="#FFF" |
5 |
android:endColor="#000" |
shape是用來定義形狀的,gradient定義該形狀裡面為漸層色填充,startColor起始顏色,endColor結束顏色,angle表示方向角度。當angle=0時,漸層色是從左向右。 然後逆時針方向轉,當angle=90時為從下往上。
實現過程:
第一步:
res/drawable/background_login.xml
[代碼]xml代碼:
1 |
<?xml version="1.0" encoding="utf-8"?> |
2 |
<shape xmlns:android="http://schemas.android.com/apk/res/android"> |
4 |
android:startColor="#FFF" |
5 |
android:endColor="#000" |
第二步:
res/layout/login.xml
[代碼]xml代碼:
1 |
<?xml version="1.0" encoding="utf-8"?> |
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
3 |
android:orientation="vertical" |
4 |
android:layout_width="fill_parent" |
5 |
android:layout_height="fill_parent" |
6 |
android:background="@drawable/background_login"> |
第三步:
[代碼]java代碼:
01 |
import android.app.Activity; |
02 |
import android.os.Bundle; |
04 |
public class LoginActivity extends Activity { |
06 |
public void onCreate(Bundle savedInstanceState) { |
07 |
super.onCreate(savedInstanceState); |
08 |
setContentView(R.layout.login); |
:
PS 中要做 藍色漸層的背景效果 或者 藍色的底色中有一些其他的圖案 怎做?
首先你前景色彩要選藍色 就是這樣 然後選擇漸層工具,在上方會出現很多選項 你自己調節下 找到你要的效果,如果直接藍色的底,那就前景色彩是藍色 直接按CTRL+DELETE填充就可以了,再把你要的圖案拖進來,希望能幫到你
android 動態設定按鈕背景的漸層顏色
在一個xml檔案中定義需要用到gradient,然後用drawable設定,大致是這樣