Android background color gradient and title Color Change

Source: Internet
Author: User

1. Android shares the same layout file in XML
I always thought that sharing the same layout file was copied after the previously written layout, Or I used layoutinflater add in Java code. But today we provide a more convenient way to use it. You can use other layout files in any of your layout files. The Code is also very simple, as shown below:
<? XML version = "1.0" encoding = "UTF-8"?>
<Linearlayoutandroid: Id = "@ + ID/framelayout01"
Android: Background = "@ drawable/layout_background" Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content" xmlns: Android = "http://schemas.android.com/apk/res/android">
<Textviewandroid: text = "welcome to use this software" Android: Id = "@ + ID/textview01"
Android: textcolor = "# f0f0f0" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"> </textview>
</Linearlayout>

This is the public layout file I defined. I named it title.
Then we use the following layout file:
<Includelayout = "@ layout/Title"
/>
The title layout can be directly obtained to our current layout file.
Tip: Use the include flag to add layout to our current layout file. You can also use the current view. findviewbyid to obtain any view in the title layout file.


2. Add the gradient effect to the background using XML
First, add a jbshape. xml file to the res/drawable folder and write the following code:

ShapeNodes are configured in the form of graphs, including squares and circles. The code above is square,

GradientNodes are mainly configured with the starting point color, the ending point color and the color, coordinates, gradient effect (180, 270 from left to right gradient, from top to bottom gradient) default from left to right
PaddingNodes are mainly configured with the spacing between top, bottom, and left.

CornersConfigure the radius of the surrounding garden feet on the node

To achieve this effect, you need to set a title. XML content as follows:

<? 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/jbshape"

Android: paddingleft = "0px"
>


3. How can I use code to customize titles automatically generated by Android?

Add the following code to oncreate:

Requestwindowfeature (window. feature_custom_title );
Setcontentview (R. layout. Main );
Getwindow (). setfeatureint (window. feature_custom_title, R. layout. Title );

Related Article

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.