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