Questions about the R.styleable

Source: Internet
Author: User

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
    1. Public Imageadapter (Context c) {
    2. Mcontext = C;
    3. TypedArray a = Obtainstyledattributes (Android. R.styleable.theme);
    4. Mgalleryitembackground = A.getresourceid (
    5. Android.  R.styleable.theme_galleryitembackground, 0);
    6. A.recycle ();
    7. }

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

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.