zoukankan      html  css  js  c++  java
  • Android背景色渐变效果(shape,gradient) (转)

    Android设置背景色可以通过在res/drawable里定义一个xml,如下:

    [代码]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>  
    View Code

    shape是用来定义形状的,gradient定义该形状里面为渐变色填充,startColor起始颜色,endColor结束颜色,angle表示方向角度。当angle=0时,渐变色是从左向右。 然后逆时针方向转,当angle=90时为从下往上。

    实现过程

    第一步:

    res/drawable/background_login.xml

    [代码]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>  
    View Code

    第二步:

    res/layout/login.xml

    [代码]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>  
    View Code

    第三步:

    [代码]java代码:

     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);  
         }  
     } 
    View Code

    效果图:

    转自:http://l62s.iteye.com/blog/1659433

  • 相关阅读:
    javascript中错误使用var造成undefined
    眼下流行的几种排课算法的介绍
    UVA 11212 IDA*
    Delphi 2007体验!
    全局钩子具体解释
    客户信用控制请求
    【2012.1.24更新】不要再在网上搜索eclipse的汉化包了!
    Android URI简单介绍
    数据结构
    关于 Head First SQL 中文版
  • 原文地址:https://www.cnblogs.com/android-for-dh/p/4423495.html
Copyright © 2011-2022 走看看