Action bar是一個標識應用程序和用戶位置的窗口功能,並且給用戶提供操作和導航模式。
Action bar的主要目的是:
1. 提供一個用於識別應用程序的標示和用戶的位置的專用空間。
2. 在不同的應用程序之間提供一致的導航和視覺體驗。 3. 突出Activity的關鍵操作(如“搜索”、“創建”、“共享”等),並且在可預見的方法內給用戶提供快捷的訪問。
參考:http://blog.csdn.net/xyz_lmn/article/details/8132420
android kitkat 有一個新的特性可以設置手機狀態欄的背景,讓手機整個界面的風格保持一致,看起來非常清爽。
GitHub上有個項目可以實現從ActionBar的顏色漸變到邊界的效果,項目地址:https://github.com/jgilfelt/SystemBarTint
import
com.readystatesoftware.systembartint.SystemBarTintManager;
SystemBarTintManager mTintManager = new SystemBarTintManager(this);
mTintManager.setStatusBarTintEnabled(true);
mTintManager.setNavigationBarTintEnabled(true);
mTintManager.setTintColor(getResources().getColor(R.color.primary_color));With
the latest updates to the Android Support v7 AppCompat Library, revision 22.1, integrating Google’s Material Design has never been easier.AppCompatActivity.
上滑toolbar消失
https://github.com/ksoichiro/Android-ObservableScrollView
動畫menu按鈕
https://github.com/balysv/material-menu
抽屜菜單的擺放和佈局通過android:layout_gravity
屬性來控制,可選值爲left、right或start、end。通過xml來佈局的話,需要把DrawerLayout作爲父容器,組界面佈局作爲其第一個子節點,抽屜佈局則緊隨其後作爲第二個子節點,這樣就做就已經把內容展示區和抽屜菜單區獨立開來,只需要分別非兩個區域設置內容即可。
mDrawerLayout.openDrawer(Gravity.LEFT);
mDrawerLayout.setDrawerListener(new
DrawerLayout.DrawerListener() {
ViewPager中間的橫線跟着屏幕的滑動而滑動
https://github.com/astuetz/PagerSlidingTabStrip
ViewPager
1)ViewPager類直接繼承了ViewGroup類,所有它是一個容器類,可以在其中添加其他的view類。
2)ViewPager類需要一個PagerAdapter適配器類給它提供數據。
3)ViewPager經常和Fragment一起使用,並且提供了專門的FragmentPagerAdapter和FragmentStatePagerAdapter類供Fragment中的ViewPager使用。
在編寫ViewPager的應用的使用,還需要使用兩個組件類分別是PagerTitleStrip類和PagerTabStrip類,PagerTitleStrip類直接繼承自ViewGroup類,而PagerTabStrip類繼承PagerTitleStrip類,所以這兩個類也是容器類。但是有一點需要注意,在定義XML的layout的時候,這兩個類必須是ViewPager標籤的子標籤,不然會出錯。
http://blog.csdn.net/lmj623565791/article/details/39121377
下拉刷新
https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh
synchronized
關鍵字,它包括兩種用法:synchronized 方法和 synchronized 塊。
1.
synchronized 方法:通過在方法聲明中加入 synchronized關鍵字來聲明 synchronized 方法。這種機制確保了同一時刻對於每一個類實例,其所有聲明爲 synchronized 的成員函數中至多隻有一個處於可執行狀態,從而有效避免了類成員變量的訪問衝突(只要所有可能訪問類成員變量的方法均被聲明爲
synchronized)。synchronized 方法的缺陷:若將一個大的方法聲明爲synchronized 將會大大影響效率
2.
synchronized 塊:通過 synchronized關鍵字來聲明synchronized 塊。語法如下:
synchronized(syncObject) {
//允許訪問控制的代碼
}
synchronized 塊是這樣一個代碼塊,其中的代碼必須獲得對象 syncObject (如前所述,可以是類實例或類)的鎖方能執行
對synchronized(this)的一些理解
Java語言的關鍵字,當它用來修飾一個方法或者一個代碼塊的時候,能夠保證在同一時刻最多隻有一個線程執行該段代碼。
一、當兩個併發線程訪問同一個對象object中的這個synchronized(this)同步代碼塊時,一個時間內只能有一個線程得到執行。另一個線程必須等待當前線程執行完這個代碼塊以後才能執行該代碼塊。
二、然而,當一個線程訪問object的一個synchronized(this)同步代碼塊時,另一個線程仍然可以訪問該object中的非synchronized(this)同步代碼塊。
三、尤其關鍵的是,當一個線程訪問object的一個synchronized(this)同步代碼塊時,其他線程對object中所有其它synchronized(this)同步代碼塊的訪問將被阻塞。
四、當一個線程訪問object的一個synchronized(this)同步代碼塊時,它就獲得了這個object的對象鎖。結果,其它線程對該object對象所有同步代碼部分的訪問都被暫時阻塞。
五、以上規則對其它對象鎖同樣適用.
Android 已經提供DisplayMetircs 類可以很方便的獲取分辨率。
DisplayMetrics display=
new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(display);//將當前窗口的一些信息放在DisplayMetrics類中
在Toolbar上有一些默認的顯示效果,注意:setNavigationIcon(),setOnMenuItemClickListener() 需要放在 setSupportActionBar之後纔會生效
if (mToolbar.getTranslationY() == toTranslationY){
return;
}
final ValueAnimator animator = ValueAnimator.ofFloat(mToolbar.getTranslationY(), toTranslationY).setDuration(200);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float translationY = (Float) animator.getAnimatedValue();
mToolbar.setTranslationY(translationY);
mContent.setTranslationY(translationY);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mContent.getLayoutParams();
lp.height = (int) (getScreenHeight() - translationY - getStatusBarHeight() - lp.topMargin);
mContent.requestLayout();
}
});
animator.start();
}