supportv7源碼
㈠ android studio 中java文件提示android.support.v7.app.actionbaractivity is deprecated怎樣處理
出這個提示的地方有寫解決辦法呀.
android.support.v7.app.ActionBarActivity is deprecated; useAppCompatActivity instead
意思是ActionBarActivity 在最新版本的support v7包裡面已經不建議使用,建議用AppCompatActivity 這個類替代它.
所以解決辦法很簡單啊,把ActionBarActivity 直接換成AppCompatActivity 就可以了.
其實如果你看源碼的話,這個AppCompatActivity 就和原來的ActionBarActivity 一模一樣.它繼承自ActionBarActivity, 但什麼也沒有復寫.
packageandroid.support.v7.app;
/**
*@deprecatedUse{@linkandroid.support.v7.app.AppCompatActivity}instead.
*/
@Deprecated
{
}
㈡ android 安卓 類似ONE卡片頁(包含圖片文字等)怎麼實現
Android5.0中向我們介紹了一個全新的控制項–CardView,從本質上看,可以將CardView看做是FrameLayout在自身之上添加了圓角和陰影效果。請注意:CardView被包裝為一種布局,並且經常在ListView和RecyclerView的Item布局中,作為一種容器使用。
下面例子來源於android學習手冊, android學習手冊包含9個章節,108個例子,源碼文檔隨便看,例子都是可交互,可運行,源碼採用android studio目錄結構,高亮顯示代碼,文檔都採用文檔結構圖顯示,可以快速定位。360手機助手中下載,排在第四個。
CardView應該被使用在顯示層次性的內容時;在顯示列表或網格時更應該被選擇,因為這些邊緣可以使得用戶更容易去區分這些內容。
使用CardView
首先,假設你的布局如同下面的形式:
<FrameLayout xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- Main Content View --> <RelativeLayout> ... </RelativeLayout> </FrameLayout>
為了使用上面的布局方式來創建一個卡片,首先你需要導入支持的依賴庫(android-support-v7-cardview的jar包)在你的build.gradle文件中。
dependencies { ... compile 'com.android.support:cardview-v7:21.0.2' }
現在將FrameLayout替換為CardView,
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- Main Content View --> <RelativeLayout> ... </RelativeLayout> </android.support.v7.widget.CardView>
就是這樣!使用依賴庫能夠保證你的程序穩定的兼容之前的版本;盡管在AndroidL和之前的Android版本中對其處理方式有所不同。
㈢ 源碼打包apk使用RecyclerView時遇到的坑
最近在做一個系統通知欄的項目叫MsgCenter。使用Android studio開發的.
使用了腳本拷貝與復制
LIBS="/Users/love/Desktop/moran2/MsgCenter/app/libs"
SRC="/Users/love/Desktop/moran2/MsgCenter/app/src/main/java/*"
RES="/Users/love/Desktop/moran2/MsgCenter/app/src/main/res"
ANDROIDMANIFEST="app/src/main/AndroidManifest.xml"
DES="/Users/love/Desktop/moran2/MsgCenter/MsgCenter"
mkdir -p $DES/src
cp -r LIBS DES
cp -r SRC DES/src
cp -r RES DES
cp -r JNI DES
cp ANDROIDMANIFEST DES
cp ANDROIDMK DES
然後提交到伺服器打包報錯:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.imoran.notification.lib, PID: 2630
java.lang.ExceptionInInitializerError
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115)
at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32)
at android.app.ActivityThread.handleBindService(ActivityThread.java:3158)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5795) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724)
Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView
at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView at android.view.LayoutInflater.createView(LayoutInflater.java:645) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.(NotificationWindowManager.java:123) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.(NotificationWindowManager.java:34) at net.imoran.notification.lib.windowmanager.NotificationWindowManager .<clinit>(NotificationWindowManager.java:111)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115)
at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32)
at android.app.ActivityThread.handleBindService(ActivityThread.java:3158)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5795) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R styleable;
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:590)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:551)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R styleable" on path: DexPathList[[zip file "/flysystem/app/mor-notification.apk"],nativeLibraryDirectories=[/system/lib64/mor-notification, /flysystem/app/mor-notification.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:590)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:551)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at net.imoran.notification.lib.manager.NotificationManager.initRootView(NotificationManager.java:51)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.initAdapterView(NotificationWindowManager.java:200)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:123)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager.<init>(NotificationWindowManager.java:34)
at net.imoran.notification.lib.windowmanager.NotificationWindowManager .(NotificationWindowManager.java:111) at net.imoran.notification.lib.windowmanager.NotificationWindowManager.getInstance(NotificationWindowManager.java:115) at net.imoran.notification.lib.service.StarStatusService.onBind(StarStatusService.java:32) at android.app.ActivityThread.handleBindService(ActivityThread.java:3158) at android.app.ActivityThread.-wrap2(ActivityThread.java) at android.app.ActivityThread H.handleMessage(ActivityThread.java:1582)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit MethodAndArgsCaller.run(ZygoteInit.java:834) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:724) Suppressed: java.lang.ClassNotFoundException: android.support.v7.recyclerview.R styleable
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 28 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
07-20 14:14:31.557 2630-2664/net.imoran.notification.lib I/System: FinalizerDaemon: finalize objects = 2695
從log中我們可以看到,
1.Binary XML file line #22: Binary XML file line #39: Error inflating class android.support.v7.widget.RecyclerView
2.同時還有這樣的 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R$styleable
3.Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R$styleable"
一開始只注意到了第一點,於是在網路上查呀查:
就發現大家的說法就是 在eclipse或者android studio上 因為sdk的版本不match,等等的。有的人說把android.support.v7.recyclerview.jar這個包換掉,換成match的版本的就好了,但我這邊因為開發方式不一樣,就又斷掉了。但是卻讓我知道了是版本的問題
後來
有的人說是
1.AndroidManifest.xml中的targetSDKVersion不對,fix -> NOK。
2.build.gradle中的某些屬性不對。fix -> NOK
因為App是獨立的apk,就去這5.0,6.0 andorid 的源碼中去找android.support.v7.recyclerview.
同時又注意到了這兩點錯誤
2.同時還有這樣的 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/recyclerview/R$styleable
3.Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.recyclerview.R$styleable"
從Log中我們可以看到
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:440)
at android.support.v7.widget.RecyclerView.<init>(RecyclerView.java:409)
RecyclerView的409 和 440 行出錯
就發現了在 frameworks/support/v7/recyclerview/src/android/support/v7/widget/RecyclerView.java中
使用到了R.styleable.RecyclerView這個屬性,而第2,3點log中出現的就是R$styleable 的錯誤。
明確了:在android6.0版本RecyclerView類中用到了R.styleable.RecyclerView這個資源。而android5.0的版本中的RecyclerView類沒用到R.styleable.RecyclerView
回到frameworks/support/v7/recyclerview/目錄下就會發現
-----------5.0 沒有res/ 文件夾
-----------6.0 則有
那麼現在中場總結一下,因為andorid5.0中的RexyclerView類中沒有使用res資源,而6.0卻使用了。同時6.0的res/資源是存在的。只能說明,我們沒有引用到,或者說是沒有把對應的資源載入,進行編譯。
問題又來了:res/資源是在哪裡載入的?
----------》 Android.mk 文件下有這么一段
發現了android-support-v7-recyclerview的身影
那這內容是什麼意思?
1.LOCAL_STATIC_JAVA_LIBARIES 本地靜態java庫。
2.LOCAL_RESOURCE_DIR 本地資源文件,默認是proct package和device package下面相應的res路徑和$(LOCAL_PATH)/res
3.LOCAL_AAPT_FLAGS += -c ldpi -c mdpi
上面指定了編譯時打包 ldpi 和mdpi 如果系統默認的是hdpi的話,那就是這三種都會裝入包中
在中場總結的時候,已經明確,是因為res資源沒有載入。
所以只需要在LOCAL_RESOURCE_DIR中加上frameworks/support/v7/recyclerview/res就可以了
Android.mk文件內容變成:
再次編譯,正常運行。
======================================================================================================
其實就是因為android的版本升級,RecyclerView 中的創建LayoutManager的方式發生了改變,舊版本里少了個 R.styleable.RecyclerView, 而在新環境下又沒將其編譯進去,故有此錯。
各位少俠也可以在 package 中的res/attrs.xml 下面自己定義一個`````
總體來說將的不是很清楚, 還請大家見諒 。。
㈣ Android Studio項目 v7包版本和依賴庫v7包版本不一致警告怎麼解決
默認使用最新版本
否則library moudle引入源碼改版本
㈤ 如何在Android Studio中添加RecyclerView-v7支持包
Android 5.0新特性中出現了一個非常牛逼的控制項——RecyclerView。默認情況下,Android Studio當前的支持包中沒有引入RecyclerView的v7包,所以當我們直接輸入Recycle時提示中沒有RecyclerView。這里要介紹的是如何在Android studio中引入支持RecyclerView的v7包。
前提是已經下載了Android Support Library支持包,一般是自動就下載好了。如果沒有下載,就打開SDK Manager下載嘍!
一、
1.在Project模式下,點開External Libraries,可以看到只有appcompat-v7-23.4.0(這是我自己下載的版本)這個v7包,通過查看其屬性可以找到源碼位置
二、其實還可以這樣做:
在源碼位置可以找到recyclerview-v7-23.4.0-sources.jar,將其復制到libs目錄下同樣可以達到目的。