关于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的类,这包括展示最终内容的非 ...
随机推荐
- JavaScript之将JS代码放在什么位置最合适
1.放到<head></head>标签里面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ ...
- SQL Server和MySql获取当前数据库每个表的列数
Sql server:(连接数据库后,点击当前数据库再新建查询) select count(c.name),o.name from syscolumns c left join sysobjects ...
- C#连接Oracle数据库基本类
C#用来连接oracle数据库的基本类: using System; using System.Collections.Generic; using System.Linq; using System ...
- C# 微信公众平台开发(4)-- 模版消息
微信公众平台开发 --发送模版消息 发送模版消息是微信服务号给某个用户发送模版消息,类似于APP的推送通知: 1.添加模版消息 在页面的左上 有一个添加功能插件的 按钮,如题 添加完成后,我们就可以在 ...
- js后缀判断
var extension=fileName.substring(fileName.lastIndexOf('.')+1);
- wamp+thinkphp环境配置
下载wamp并安装,启动wamp,会出现一个小图标,然后点击它——>Start All Services.我点击之后是橙色,不是绿色.绿色代表成功启动.我是IIS占用了80端口的缘故,所以我修改 ...
- Mac系统下下删除加锁文件方法|使用终端命令强制清除废纸篓中的文件
链接地址1:http://jingyan.baidu.com/article/fdffd1f8e39403f3e98ca195.html 在Mac OS X下,无法删除的文件无外乎三种情况:1,文件( ...
- 原生js实现的轮播图,易用+可多用
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 托管服务帐号(Managed Service Account)
托管服务帐号是绑定到单独的机器上,并且仅用于服务所用,所以不能用来登录. 创建托管帐号,不需要指定密码,密码会由活动目录自动管理.并且根据密码策略(默认30天)自动刷新,期间不影响服务. 在创建完之后 ...
- maven 添加自己的包
mvn install:install-file -Dfile=d:/flea.jar -DgroupId=com.flea.bussiness -DartifactId=flea -Dversion ...