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