Android background gradient (shape, gradient)

Source: Internet
Author: User

To set the background color, you can define an XML file in RES/drawable, as shown below:

<? 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 is used to define the shape. Gradient defines the gradient fill in the shape, startcolor starting color, endcolor ending color, angle indicates the direction angle. When angle is set to 0, the gradient changes from left to right. Then it turns counter-clockwise. When angle is 90, it goes from bottom to top.

Implementation process:

Step 1:

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>

Step 2:

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>

Step 3:

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

:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.