原来想直接想调用程序的东西,但是使用R.styleable的时候 eclipse不能解析了,后来发现原来被删除了此方法

  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. }

这种方法也就不能用了

然后

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的问题的更多相关文章

  1. android r.styleable是什么或报错

    r.styleable 是自定义控件 自定义控件写好的后,需要在res-value-attrs.xml中定义,如: <declare-styleable name="SlidingMe ...

  2. Android android.support.v7.appcompat.R$styleable

    引入第三方jar或者library时比如自定义控件.突然报如下错误: 07-17 09:22:25.430: E/CrashHandler(14102): Caused by: android.vie ...

  3. 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. ...

  4. OpenCV 4.0.1 找不到R.styleable解决

    OpenCV 4.0.1作为模块导入Android Studio会有找不到R.styleable的问题. 解决方法 1.导入模块前 将 opencv-4.0.1-android-sdk\OpenCV- ...

  5. Android中View自己定义XML属性具体解释以及R.attr与R.styleable的差别

    为View加入自己定义XML属性 Android中的各种Widget都提供了非常多XML属性,我们能够利用这些XML属性在layout文件里为Widget的属性赋值. 例如以下所看到的: <Te ...

  6. 深入理解Android 自定义attr Style styleable以及其应用

    相信每一位从事Android开发的猿都遇到过需要自己去自定义View的需求,如果想通过xml指定一些我们自己需要的参数,就需要自己声明一个styleable,并在里面自己定义一些attr属性,这个过程 ...

  7. Android Canvas不能换行,或者不识别\n,\r\n的解决方案

    在使用Canvas绘制文本的时候,如果要绘制的字符串含有\r\n,\n换行的时候,会识别不出来,当成空格绘制出来. 解决方案: 1.使用StaticLayout来实现,具体代码如下: TextPain ...

  8. 虾扯蛋:Android View动画 Animation不完全解析

    本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...

  9. android自定义控件一站式入门

    自定义控件 Android系统提供了一系列UI相关的类来帮助我们构造app的界面,以及完成交互的处理. 一般的,所有可以在窗口中被展示的UI对象类型,最终都是继承自View的类,这包括展示最终内容的非 ...

随机推荐

  1. 【解决方法】You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)

    出现场景: 正常调试是没有问题的,但是在Archive的时候,报出了这个错误. 问题详情: (null): URGENT: all bitcode will be dropped because ‘x ...

  2. Android应用开发基础篇(4)-----TabHost(选项卡)

    一.概述 TabHost是一种用来显示标签的组件,不清楚?看一下来电通这个应用就知道了.这个组件用起来与其他组件不太一样,它需要继承TabActivity这个类,还有它的布局文件与我们平时用的也有些不 ...

  3. .net mvc System.Web.Optimization 、System.Data.Entity.Infrastructure找不到

    在MVC4的开发中,如果在App_Start目录下BundleConfig.cs类没有找不到引用System.Web.Optimization,可以使用程序包管理控制台进行安装到使用的项目 打开 工具 ...

  4. BAE初试

    BAE是百度的应用开发托管平台.  支持python nodejs java php 这几个环境~ 我在BAE上面搭建了1个wordpress. 记录下开启一个app的过程. 下面是所需工具 ---版 ...

  5. AngularJs 简单入门

    1.AngularJs 是什么以及应用程序组成的三部分 AngularJS是一个开发动态Web应用的框架.它让你可以使用HTML作为模板语言并且可以通过扩展的HTML语法来使应用组件更加清晰和简洁.它 ...

  6. OpenCV 开发环境环境搭建(win10+vs2015+opencv 3.0)

    OpenCV 3.0 for windows(下载地址:http://opencv.org/): 本测试中,OpenCV安装目录:D:\Program Files\opencv,笔者操作系统为64位. ...

  7. JavaScriptCore.framework基本用法(二)

    接着上节我们讲到的iOS调用js 下来我们使用js调用iOS js调用iOS分两种情况 一,js里面直接调用方法 二,js里面通过对象调用方法 首先我们看第一种,直接调用方法. 其中用到了iOS的bl ...

  8. 经典阅读-《Effective C++》Item1:视C++为一个联邦语言

    C++已经是个多重范型编程语言(multiparadigm programming language),一个同时支持过程形式(procedural).面向对象形式(object-oriented).泛 ...

  9. python --appium搭建环境过程 ---新手总结(大牛勿喷,新手互相交流)

    首先安装python 安装包:https://yunpan.cn/cSdYZqjJ4xDZ3  访问密码 4bf9 1.安装pip   cd 到pip安装包  python setup.py inst ...

  10. object-c 协议(Protocols)和代理(Delegation)的学习

    代理是Object-C中的一个重要机制,他可以将面向对象编程的封装特性进一步加强,不是自己负责的事情坚决不做,而是转而让对应的事情负责人(代理)去做.相反如果是自己需要负责的事情(作为别人的代理),会 ...