前兩天Google更新了Support Library23.2 過年來就一直在趕項目 學習的時間也少了很多 但今年我給自己也規定了一周最少也要寫一篇博客 于是今天擠著時間看了看已經有些大神都已經做出Demo 一些坑基本都可以Google出來了 (這就叫比自己優秀的人比自己更努力 好吧其實還是自己太懶了)ok Let's study
更新內容
- support-vector-drawable and animated-vector-drawable
- AppCompat DayNight theme
- Bottom Sheets
- ** RecyclerView**
- ** Custom Tabs**
- ** Leanback for Android TV**
官方地址 http://android-developers.blogspot.com/2016/02/android-support-library-232.html
部分代碼參考自(出于對他人尊重永遠把他人的鏈接放在前面):https://github.com/liaohuqiu/android-support-23.2-sample
下方有本博客源碼
AppCompat DayNight theme
主題切換當然我們就需要兩份主題對應"day" "night"
night
day
相應的xml布局中需要設置背景android:background="?android:colorBackground"
這樣對應的設置就OK了
代碼上也很簡單
白天模式:
<pre><code>getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
recreate();</code></pre>
夜晚模式:<pre><code>getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);recreate();</code></pre>
自動模式:<pre><code>AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);</code></pre>
官方文檔是這樣描述自動模式的
When using AppCompatDelegate.MODE_NIGHT_AUTO, the time of day and your last known location (if your app has the location permissions) are used to automatically switch between day and night, while MODE_NIGHT_NO and MODE_NIGHT_YES forces the theme to never or always use a dark theme, respectively.
它會根據最后一次定位來選擇模式,同時也可以強制改變主題模式
Bottom Sheets
官方中有講此次更新Bootom Sheets是支持了所有View 并支持多個回調事件
STATE_COLLAPSED 折疊狀態。可通過app:behavior_peekHeight來設置默認顯示的高度。
STATE_SETTING 拖拽松開之后到達終點位置(collapsed or expanded)前的狀態。
STATE_EXPANDED 完全展開的狀態。
STATE_HIDDEN 隱藏狀態。默認是false,可通過app:behavior_hideable
屬性設置。
STATE_DRAGGING 被拖拽狀態
幾乎不用寫什么代碼就可以有效果了(!--我承認UI是有點丑)
同時谷歌還提供了一個類可以完成類似的操作BottomSheetDialog使用也很簡單
最后貼上整個效果
關于RecyclerView最主要的是他支持了WRAP_CONTENT
源碼地址:
https://github.com/EasonHolmes/AboutSupport23.2/tree/master