1,定义一个Android.mk
================
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
MAINLIB_ABS_SRC_DIR := $(LOCAL_PATH)/../
MAINLIB_SRC_DIR := ..
src_files:=$(call all-java-files-under,$(MAINLIB_SRC_DIR))
aidl_files:=$(call all-Iaidl-files-under,$(MAINLIB_SRC_DIR))
LOCAL_SRC_FILES := \
$(src_files) \
$(aidl_files)
LOCAL_AIDL_INCLUDES := \
$(MAINLIB_ABS_SRC_DIR)/sensors/java \
$(MAINLIB_ABS_SRC_DIR)/webkit/java \
$(MAINLIB_ABS_SRC_DIR)/ui/java
LOCAL_MODULE:= com.xxx.android.frameworks
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
LOCAL_DX_FLAGS := --core-library
#include R.java of resource apk
LOCAL_INTERMEDIATE_SOURCES := $(framework-res-source-path)/my/own/
resource/apk/R.java
include $(BUILD_JAVA_LIBRARY)
==============================
2, 在com/xxx/android/frameworks下开发java库;
3,库的资源作为一个apk的Android.mk
==============================
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_PACKAGE_NAME := my-lib-res
LOCAL_CERTIFICATE := platform
# Tell aapt to create "extending (non-application)" resource IDs,
LOCAL_AAPT_FLAGS := -x
LOCAL_MODULE_TAGS := user
# Install this alongside the libraries.
LOCAL_MODULE_PATH := $(TARGET_OUT_JAVA_LIBRARIES)
# Create package-export.apk, which other packages can use to get
# PRODUCT-agnostic resource data like IDs and type definitions.
LOCAL_EXPORT_PACKAGE_RESOURCES := true
include $(BUILD_PACKAGE)
===========================================
4,资源apk的AndroidManifest.xml
package="com.abc.android.widget">
红字是在自定义库(com.xxx.android.frameworks.jar)中的包名。
5,在attrs.xml中自定义widget的style
.....
6, 在widget文件中
public MyWidgeFlowView(Context context, AttributeSet attrSet, int defStyle) {
super(context, attrSet, defStyle);
TypedArray a = context.obtainStyledAttributes(attrSet,
R.styleable.WidgeFlowView, defStyle, 0);
mIsMainItemLive = a.getBoolean(R.styleable.WidgeFlowView_isMainItemLive, false);
mMainItemWidth = a.getDimensionPixelSize(R.styleable.WidgetFlowView_mainItemWidth, 256);
....
a.recycle();
}
5,make编译,结果在com.xxx.android.frameworks.jar
如何使用
1,在AndroidManifest.xml中加入
2,如果在layout文件中用到自定义库中的类
xmlns:abc.res="com.abc.android.widget"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/card_wall"
android:orientation="vertical">
....
<com.abc.android.widget.XXXView android:id="@+id/widget_id"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"
abc.res:mainItemWidth="185dip"
abc.res:mainItemHeight="185dip"
abc.res:mainItemOffsetY="-10dip"/>
红字是widget在自定义库中的包名
3,在java文件中用要
import
com.abc.android.widget.XXXView;
阅读(7690) | 评论(1) | 转发(1) |