標籤:漸層 super shape login rri state pre parent linear
Android設定背景色可以通過在res/drawable裡定義一個xml,如下:
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#FFF" android:endColor="#000" android:angle="45" /></shape>
shape是用來定義形狀的,gradient定義該形狀裡面為漸層色填充,startColor起始顏色,endColor結束顏色,angle表示方向角度。當angle=0時,漸層色是從左向右。 然後逆時針方向轉,當angle=90時為從下往上。
實現過程:
第一步:
res/drawable/background_login.xml
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#FFF" android:endColor="#000" android:angle="45" /></shape>
第二步:
res/layout/login.xml
<?xml version="1.0" encoding="utf-8"?><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/background_login"></LinearLayout>
第三步:
import android.app.Activity;import android.os.Bundle; public class LoginActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); }}
Android背景漸層色(shape,gradient)