自定义控件和Android Library Project 知识链接汇总

最近在研究andorid自定义控件和分项目编写,以下链接给了我很大帮助,感谢这些乐于分享的人。不敢独享,分享一下:

1.android 自定义id

在res\values建立ids.xml文件,格式和系统一致

2.Android 中自定义控件和属性(attr.xml,declare-styleable,TypedArray)的方法和使用

3.Android 自定义View自定义属性的声明

4.创建和使用Android library工程

5.Android学习系列(6)--App模块化及工程扩展

6.android 引用外部库工程

7.Managing Projects from Eclipse with ADT  这个事官方的

8.关于Android-library自定义属性的使用简介

9.Issue 9656 Library projects don't support custom XML attributes for custom classes.

10.Help with a custom View attributes inside a Android Library Project


8-10 提供解决Android-library自定义属性的杯具

8中的

注意,上面的lfchart应用的是主工程的包名,而不是控件的包名。

这句话很有用,以下两种分案,都是围绕着它。


下面英文比较简单,我就不翻译了啊

9中的

Comment 20 by wolfram....@gmail.comJul 27, 2011

I might have just found quite a simple work-arround:
Steps:
1. define a String resource in the library project with your library package:
 <string name="NS">http://schemas.android.com/apk/res/com.company.yourLIBRARYproject</string>
2. define the same resource for your app project with your app package: 
<string name="NS">http://schemas.android.com/apk/res/com.company.yourAPPproject</string>

3. replace all custom namespace definitions in library and app project with 
 xmlns:custom="@string/NS" 
(instead of xmlns:custom="http://schemas.android.com/apk/res/com.company.yourLIBRARYproject" and xmlns:custom="http://schemas.android.com/apk/res/com.company.yourAPPproject" 
)
Attributes can now be called the normal way custom:attribute ="value"
可以,我试过。


10中的

After two hours of work with my coworker, we figure out how to make this work : Library : com.library mywidget.java with a class MyWidget

attrs.xml :

<declare-styleable name="MyWidget">

and put your attr

Instead of having your layout (main.xml for example) with your widget declared in it, juste create a my_widget.xml in the layout foler of your library. my_widget.xml

<?xml version="1.0" encoding="utf-8"?>
<com.library.MyWidget
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:widget="http://schemas.android.com/apk/res/com.library"
    android:id="@+id/your_id"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    widget:your_attr>
</com.library.MyWidget>

for including it in your layout, juste put

<include layout="@layout/my_widget"></include>

App : com.myapp

You juste have to duplicate my_widget.xml here, and change the namespace :

<?xml version="1.0" encoding="utf-8"?>
<com.library.MyWidget
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:widget="http://schemas.android.com/apk/res/com.myapp" <---- VERY IMPORTANT
    android:id="@+id/your_id"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    widget:your_attr>
</com.library.MyWidget>

And normally it will work !

可以,我试过。


Android-library真是个杯具啊,以上两种方法,都很dt。不知道有谁还有更好的解决方法,和大家分享一下。

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值