Android_declare-styleable _ properties of Custom Controls

Source: Internet
Author: User

Android_declare-styleable _ properties of Custom Controls
1. simple instance

(1) define an attrs. xml file under the res/values File

  
      
                       
   
  
(2) Layout File Usage
      
       
   
  
(3). custom control settings
public class MyTextView extends TextView {public MyTextView(Context context) {this(context, null);}public MyTextView(Context context, AttributeSet attrs) {this(context, attrs, 0);}public MyTextView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.my);String str = a.getString(R.styleable.my_content);setText(str + "@@");a.recycle();}}

2. Other remarks

(1 ). the format in each attr should be of the specified type, string/integer/dimension/reference (reference R file)/color/enum/boolean. Multiple formats can be separated by |, all others are the same, instance enum

                      
           
       
  
(2) XML namespace rules in the layout file, xmlns: toolbar = http://schemas.android.com/apk/res/?packagename]

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.