Android custom widget styles: how to put them into a namespace?

前端 未结 4 1376
情话喂你
情话喂你 2021-01-01 17:17

In the ApiDemos, there is a view example called Gallery1 which declares a custom style in attrs.xml, as such:


            


        
4条回答
  •  醉梦人生
    2021-01-01 17:44

    create a xml file and paste this below code and put in res->values folder

    
        
    
    

    and then copy below code

    TypedArray typedArray=this.obtainStyledAttributes(R.styleable.Gallery1);
            int back=typedArray.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
            typedArray.recycle();
    

    and set in ur widget background i mean imageView.setBackgroundResource(back);

提交回复
热议问题