关于R.styleable的问题
原来想直接想调用程序的东西,但是使用R.styleable的时候 eclipse不能解析了,后来发现原来被删除了此方法
- public ImageAdapter(Context c) {
- mContext = c;
- TypedArray a = obtainStyledAttributes(android.R.styleable.Theme);
- mGalleryItemBackground = a.getResourceId(
- android.R.styleable.Theme_galleryItemBackground, 0);
- a.recycle();
- }
这种方法也就不能用了
然后
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
唯一要做的就是自己去做一个styleable
res\values
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Gallery1">
<attr name="android:galleryItemBackground" />
</declare-styleable>
</resources>
////////////////
以launcher为例说明自定义控件的属性:
1、 在layout里面定义控件,如:
<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、 该控件workspace下面有一个属性是launcher:defaultScreen,这属性不是ViewGroup(workspace类是继承于ViewGroup)所定义的属性,那么我们可以在\res\values里面的attrs.xml里面定义
具体的定义方法如下:
<resources>
<declare-styleable name="Workspace">
<attr name="defaultScreen" format="integer" />
</declare-styleable>
</resources>
引用方法是 先申明xmlns:launcher="http://schemas.android.com/apk/res/com.junction.launcher"(R.java),这样就可以使用launcher:defaultScreen。
3、 这样我们在Workspace的类里面就可以去除在layout里面对该属性的赋值,方法如下:
Int mDefaultScreen;
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);
a.recycle();
++++++++++++++++++++++++++++++
自己案例:可看一个gifPlayer的demo程序。
其他案例:http://blog.csdn.net/Android_Tutor/archive/2010/04/20/5508615.aspx
关于R.styleable的问题的更多相关文章
- android r.styleable是什么或报错
r.styleable 是自定义控件 自定义控件写好的后,需要在res-value-attrs.xml中定义,如: <declare-styleable name="SlidingMe ...
- Android android.support.v7.appcompat.R$styleable
引入第三方jar或者library时比如自定义控件.突然报如下错误: 07-17 09:22:25.430: E/CrashHandler(14102): Caused by: android.vie ...
- where can I find source of com.android.internal.R.styleable.AlertDialog_multiChoiceItemLayout?
I want to modify Alert dialog multi select layout. For my program I want two line multi-select item. ...
- OpenCV 4.0.1 找不到R.styleable解决
OpenCV 4.0.1作为模块导入Android Studio会有找不到R.styleable的问题. 解决方法 1.导入模块前 将 opencv-4.0.1-android-sdk\OpenCV- ...
- Android中View自己定义XML属性具体解释以及R.attr与R.styleable的差别
为View加入自己定义XML属性 Android中的各种Widget都提供了非常多XML属性,我们能够利用这些XML属性在layout文件里为Widget的属性赋值. 例如以下所看到的: <Te ...
- 深入理解Android 自定义attr Style styleable以及其应用
相信每一位从事Android开发的猿都遇到过需要自己去自定义View的需求,如果想通过xml指定一些我们自己需要的参数,就需要自己声明一个styleable,并在里面自己定义一些attr属性,这个过程 ...
- Android Canvas不能换行,或者不识别\n,\r\n的解决方案
在使用Canvas绘制文本的时候,如果要绘制的字符串含有\r\n,\n换行的时候,会识别不出来,当成空格绘制出来. 解决方案: 1.使用StaticLayout来实现,具体代码如下: TextPain ...
- 虾扯蛋:Android View动画 Animation不完全解析
本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...
- android自定义控件一站式入门
自定义控件 Android系统提供了一系列UI相关的类来帮助我们构造app的界面,以及完成交互的处理. 一般的,所有可以在窗口中被展示的UI对象类型,最终都是继承自View的类,这包括展示最终内容的非 ...
随机推荐
- c#观察者模式学习笔记(1)
c#中的观察者是一种逻辑上很重要的角色,在服务端,观察者是服务端的通讯员,它将事件与业务紧密的结合,彼此又能按照逻辑进行分离. 实现方法为: (1)声明事件的委托原型,作为事件订阅的回调. (2)使用 ...
- Identity Card(水题)
Identity Card Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- CSS–Some Structure
Some Structure About CSS Layout Position,Layer[层次] Box Model Visual Formatting Model BFC[block forma ...
- 深入解读JavaScript面向对象编程实践
面向对象编程是用抽象方式创建基于现实世界模型的一种编程模式,主要包括模块化.多态.和封装几种技术.对JavaScript而言,其核心是支持面向对象的,同时它也提供了强大灵活的基于原型的面向对象编程能力 ...
- Jquery简单动画的实现记录
<div style="background:#98bf21;height:100px;width:100px;"> //从元素当前所在位置,往下消失 $(docume ...
- ASP.NET之电子商务系统开发-4(二级分类)
一.前言 继上次的订单,这是第四篇.记录一下分类和筛选.这功能是最后做的,因为我完全不懂其原理.后来通过同学的指导(一位很有天赋的同学,比我牛逼一个层次,同样是高三.:D),终于也是完成了.在写这篇博 ...
- ZOJ3689 Digging(01背包)
#include <iostream> #include <cstdio> #include<cmath> #include<algorithm> #i ...
- iOS:ABPeoplePickerNavigationController系统通讯录使用
昨天因项目需求要访问系统通讯录获取电话号码,于是乎从一无所知,开始倒腾,倒腾了一下午,总算了弄好了.写这边博客是为了记录一下,自己下一次弄的时候就别在出错了.同时,有和我一样的菜鸟能够避免走一下弯路. ...
- windows hook (转)
http://blog.csdn.net/friendan/article/details/12226201 原文地址:http://blog.sina.com.cn/s/blog_628821950 ...
- linux下安卓编译apk环境搭建
ubuntu下linux安卓编译环境搭建. 配置好编译环境 (前提是已经安装了jdk,可以用java -verison 命令查看) 一.设置环境变量 用vi ~/.bashrc 打开编译环境 JA ...