Originally wanted to directly want to invoke the program, but when using r.styleable eclipse can not parse, and later found that the original was deleted this method
Java code
- Public Imageadapter (Context c) {
- Mcontext = C;
- TypedArray a = Obtainstyledattributes (Android. R.styleable.theme);
- Mgalleryitembackground = A.getresourceid (
- Android. R.styleable.theme_galleryitembackground, 0);
- A.recycle ();
- }
It's not going to work that way.
And then
Public Imageadapter(ContextC) {Mcontext=C;TypedArrayA= C. (r. Styleable. Gallery1 mgalleryitembackground = A.< Span class= "PLN" >getresourceid (r. Styleable. Gallery1_android_galleryitembackground, 0 a. /span>
The only thing to do is to make a styleable yourself.
Res\values
<? XML Version= "1.0" Encoding= "utf-8" ?> <resources> <declare-styleable name< Span class= "pun" >= "Gallery1" > span class= "tag" ><attr name= "Android: Galleryitembackground " /> </declare-styleable> </RESOURCES>
////////////////
Take launcher as an example to illustrate the properties of a custom control:
1. Define controls in layout, such as:
<com.junction.launcher.draglayer
xmlns:android= "Http://schemas.android.com/apk/res/android"
xmlns:launcher= "Http://schemas.android.com/apk/res/com.junction.launcher"
Android:id= "@+id/drag_layer" android:layout_width= "match_parent" android:layout_height= "Match_parent" >
<com.android.launcher.workspace
Android:id= "@+id/workspace"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
launcher:defaultscreen= "1" >
<include android:id= "@+id/cell1" layout= "@layout/workspace_screen"/>
<include android:id= "@+id/cell2" layout= "@layout/workspace_screen"/>
<include android:id= "@+id/cell3" layout= "@layout/workspace_screen"/>
</com.android.launcher.Workspace>
2, the control workspace below a property is Launcher:defaultscreen, this property is not ViewGroup (workspace class is inherited from ViewGroup) the properties defined, then we Can be defined within the attrs.xml inside the \res\values.
The specific definition is as follows:
<resources>
<declare-styleable name= "Workspace" >
<attr name= "Defaultscreen" format= "integer"/>
</declare-styleable>
</resources>
The reference method is to declare xmlns:launcher= "Http://schemas.android.com/apk/res/com.junction.launcher" (R.java) so that you can use the Launcher:defaultscreen.
3, so that we in the workspace class can be removed in the layout of the value of the property assignment, the method is as follows:
Int Mdefaultscreen;
TypedArray a = Context.obtainstyledattributes (Attrs, R.styleable.workspace, Defstyle, 0);
Mdefaultscreen = A.getint (R.styleable.workspace_defaultscreen, 1);
A.recycle ();
++++++++++++++++++++++++++++++
Own case: Can see a gifplayer demo program.
Other cases: http://blog.csdn.net/Android_Tutor/archive/2010/04/20/5508615.aspx
Questions about the R.styleable