zoukankan      html  css  js  c++  java
  • 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">
    3     <gradient
    4         android:startColor="#FFF"
    5         android:endColor="#000"
    6         android:angle="45" />
    7 </shape>

    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">
    3     <gradient
    4         android:startColor="#FFF"
    5         android:endColor="#000"
    6         android:angle="45" />
    7 </shape>

    第二步:

    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">
    7 </LinearLayout>

    第三步:

    [代码]java代码:

    01 import android.app.Activity;
    02 import android.os.Bundle;
    03   
    04 public class LoginActivity extends Activity {
    05     @Override
    06     public void onCreate(Bundle savedInstanceState) {
    07         super.onCreate(savedInstanceState);
    08         setContentView(R.layout.login);
    09     }
    10 }

    效果图:

    渐变颜色效果图

  • 相关阅读:
    linux | 管道符、输出重定向
    php 升级php5.5 、php7
    mysql 启动失败
    centos7.2安装phpmyadmin
    php file_get_contents失败[function.file-get-contents]: failed to open stream: HTTP request failed!解决
    go println与printf区别
    前端 head 中mate 详解
    centos 7 安装mysql
    iOS数据持久化—数据库SQLite模糊查询
    C 语言字符串和格式化输入与输出
  • 原文地址:https://www.cnblogs.com/xiaochao1234/p/3863563.html
Copyright © 2011-2022 走看看