If you don't want to say more, let's share it with you:
- Android shares the same layout file in XML
- Add gradient effects to the background using XML
- How can I use code to customize titles automatically generated by Android?
- In activitygroup, how does one access the view of a sub-activity and operate on it to change the UI?
Let's talk about the above four points. These seem to be not found in the search. I will talk about them today. It seems that I haven't updated my blog's Android articles in a few weeks, the ebook source code promised earlier has not kept up. Recently, I was lazy. I just bought an iPad, and I 've been playing, so I 've ruined my studies .....
Okay. Let's talk about it one by one. 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"?>
<Linearlayout Android: 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">
<Textview Android: 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:
<Include layout = "@ 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
To achieve the gradient effect for the background, the most traditional method is to use psto make a gradient, but I am too lazy to learn the PS technology, and I am too lazy to add an image to the application, here we use a great method provided by Google to solve the background gradient function.
First, add an XML file to the drawable folder and write the following code:
<? XML version = "1.0" encoding = "UTF-8"?>
<Shape xmlns: Android = "http://schemas.android.com/apk/res/android">
<Gradient Android: startcolor = "#52 adcd" Android: endcolor = "#1c87b1"
Android: angle = "270.0" type = "parmname" text = "parmname">
</Gradient>
</Shape>
The corresponding attributes are relatively simple. We will not introduce them here. Android: Shape = "rectangle" indicates that the gradient shape is a rectangle. Android: angle = "270.0" indicates that the angle is 270. The gradient from top to bottom is changed. If I change to 0, the gradient is changed from left to right, if you change the gradient by 90.0, the gradient will go down from below. You can change the parameters to try the effect.
Send one:
Tip: The angle is 0.
3. How can I use code to customize titles automatically generated by Android?
This is relatively simple and only uses three codes:
Requestwindowfeature (window. feature_custom_title );
Setcontentview (R. layout. Main );
Getwindow (). setfeatureint (window. feature_custom_title, R. layout. Title );
The effect is as follows:
Tip: the position of the three statements must be as above.
4. In activitygroup, how does one access the view of a sub-activity and operate on it to change the UI?
To learn how to operate on the layout view of a sub-activity in activitygroup, first understand how to put the activity into activitygroup. Here I encapsulate a small Method for your reference:
/**
* Set a dynamic activity view object for a viewgroup of activitygroup.
*
* @ Param Context
* @ Param localactivitymanager object
* @ Param activitygroup: Activity inclusion
* Viewgroup)
* @ Param specifies the activity class to be enabled through intent.
* @ Param start Activity
* Set ID
*/
Public
Static
Void getview (context, localactivitymanager Lam,
Linearlayout layout_load, class <?> CLS, string ID ){
Intent intent =
New intent (context, CLS );
Intent. addflags (intent. flag_activity_clear_top );
Window W = Lam. startactivity (ID, intent );
View v = W. getdecorview ();
Layout_load.removeallviews ();
Layout_load.setpadding (5, 5, 5, 5 );
Layout_load.addview (v, new linearlayout. layoutparams (
Linearlayout. layoutparams. fill_parent,
Linearlayout. layoutparams. fill_parent ));
}
Use the following code on the activitygroup page:
Private localactivitymanager manager; // declare a localactivitymanager object
Manager = getlocalactivitymanager (); // get this object
Interface initialization:
/**
* Initialization
*/
Void Init (){
Comonhelp. getview (this, Manager, main, preferenceset. class, "SWC ");
}
With the Set ID, you can get the current activity.
Below is a piece of code I have used for reference:
Sharedpreferences. Editor editor = getsharedpreferences (
"Com. SWC. yaomei_preferences ",
Activity. mode_private). Edit ();
Localactivitymanager manager = getlocalactivitymanager ();
Preferenceactivity acitivty = (preferenceactivity) Manager
. Getactivity ("SWC ");
For (INT I =
0; I <
9; I ++ ){
Editor. putstring ("Key _"
+ I, "N/");
Preferencescreenext ext = (preferencescreenext) acitivty
. Findpreference ("Key _"
+ I );
Relativelayout layout = (relativelayout) ext
. Getlayout ();
Textview summary = (textview) layout. getchildat (1 );
Summary. settext ("N/");
}
Editor. Commit ();
System. GC ();
The preferenceactivity above gets a preferenceacitity. Because I want to modify the preference corresponding to the activitygroup, I want to get a preferenceacitity here. If you are a normal activity, just get an activity object, the subsequent operations are the same.
Well, although it's just a few tips, it's quite practical...